Skip to content

Add static type analysis with PHPStan #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
/.phive/
/Doxyfile export-ignore
/phpcs.xml export-ignore
/phpstan-baseline.neon export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml export-ignore
/tests export-ignore
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,41 @@ jobs:
if: "${{ matrix.coverage != 'none' && env.CODACY_PROJECT_TOKEN != '' }}"
run: |
./vendor/bin/codacycoverage clover build/coverage/xml

phpstan:
name: PHPStan

runs-on: ubuntu-20.04

needs: [ php-lint ]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: "composer:v2, phive"
coverage: none

- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ~/.cache/composer
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-

- name: Install Composer dependencies
run: |
composer update --with-dependencies --no-progress;
composer show;

- name: Install development tools
run: |
echo y | phive --no-progress update phpstan;

- name: Run PHPStan
run: "composer ci:php:stan"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.phive/*
/.php_cs.cache
/composer.lock
/phpstan.neon
/vendor/
!/.phive/phars.xml
1 change: 1 addition & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<phive xmlns="https://phar.io/phive">
<phar name="phpcbf" version="^3.6.0" location="./.phive/phpcbf.phar" copy="false" installed="3.6.0"/>
<phar name="phpcs" version="^3.6.0" location="./.phive/phpcs.phar" copy="false" installed="3.6.0"/>
<phar name="phpstan" version="^0.12.88" installed="0.12.88" location="./.phive/phpstan.phar" copy="false"/>
</phive>
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
"@ci:static"
],
"ci:php:sniff": "@php ./.phive/phpcs.phar lib tests",
"ci:php:stan": "@php ./.phive/phpstan.phar",
"ci:static": [
"@ci:php:sniff"
"@ci:php:sniff",
"@ci:php:stan"
],
"fix:php": [
"@fix:php:sniff"
],
"fix:php:sniff": "@php ./.phive/phpcbf.phar lib tests"
"fix:php:sniff": "@php ./.phive/phpcbf.phar lib tests",
"phpstan:baseline": "@php ./.phive/phpstan.phar --generate-baseline"
}
}
27 changes: 27 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
parameters:
ignoreErrors:
-
message: "#^Class Sabberworm\\\\CSS\\\\Parsing\\\\ParserState constructor invoked with 1 parameter, 2\\-3 required\\.$#"
count: 1
path: lib/Sabberworm/CSS/CSSList/CSSList.php

-
message: "#^Access to an undefined property Sabberworm\\\\CSS\\\\Parsing\\\\ParserState\\:\\:\\$oParserHelper\\.$#"
count: 1
path: lib/Sabberworm/CSS/Parsing/ParserState.php

-
message: "#^Access to an undefined property Sabberworm\\\\CSS\\\\Property\\\\Charset\\:\\:\\$aComments\\.$#"
count: 5
path: lib/Sabberworm/CSS/Property/Charset.php

-
message: "#^Class PHPUnit\\\\Framework\\\\TestCase referenced with incorrect case\\: PHPunit\\\\Framework\\\\TestCase\\.$#"
count: 1
path: tests/Sabberworm/CSS/OutputFormatTest.php

-
message: "#^Class PHPUnit\\\\Framework\\\\TestCase referenced with incorrect case\\: PHPunit\\\\Framework\\\\TestCase\\.$#"
count: 1
path: tests/Sabberworm/CSS/ParserTest.php

Comment on lines +1 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I thought there’d be more

Copy link
Collaborator Author

@oliverklee oliverklee May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also because we're starting at level 0. 😄 (The PHPStan levels go up to level 8 …)

16 changes: 16 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
includes:
- phpstan-baseline.neon

parameters:
parallel:
# Don't be overly greedy on machines with more CPU's to be a good neighbor especially on CI
maximumNumberOfProcesses: 5

level: 0

scanDirectories:
- %currentWorkingDirectory%/lib/
- %currentWorkingDirectory%/tests/
paths:
- %currentWorkingDirectory%/lib/
- %currentWorkingDirectory%/tests/