Skip to content

Commit abf3975

Browse files
authored
Merge pull request #227 from oliverklee/feature/phpstan
Add static type analysis with PHPStan
2 parents 444361c + 06044b9 commit abf3975

File tree

7 files changed

+90
-2
lines changed

7 files changed

+90
-2
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
/.phive/
55
/Doxyfile export-ignore
66
/phpcs.xml export-ignore
7+
/phpstan-baseline.neon export-ignore
8+
/phpstan.neon.dist export-ignore
79
/phpunit.xml export-ignore
810
/tests export-ignore

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,41 @@ jobs:
7878
if: "${{ matrix.coverage != 'none' && env.CODACY_PROJECT_TOKEN != '' }}"
7979
run: |
8080
./vendor/bin/codacycoverage clover build/coverage/xml
81+
82+
phpstan:
83+
name: PHPStan
84+
85+
runs-on: ubuntu-20.04
86+
87+
needs: [ php-lint ]
88+
89+
steps:
90+
- name: Checkout
91+
uses: actions/checkout@v2
92+
93+
- name: Install PHP
94+
uses: shivammathur/setup-php@v2
95+
with:
96+
php-version: 7.4
97+
tools: "composer:v2, phive"
98+
coverage: none
99+
100+
- name: Cache dependencies installed with composer
101+
uses: actions/cache@v1
102+
with:
103+
path: ~/.cache/composer
104+
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
105+
restore-keys: |
106+
php${{ matrix.php-version }}-composer-
107+
108+
- name: Install Composer dependencies
109+
run: |
110+
composer update --with-dependencies --no-progress;
111+
composer show;
112+
113+
- name: Install development tools
114+
run: |
115+
echo y | phive --no-progress update phpstan;
116+
117+
- name: Run PHPStan
118+
run: "composer ci:php:stan"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.phive/*
22
/.php_cs.cache
33
/composer.lock
4+
/phpstan.neon
45
/vendor/
56
!/.phive/phars.xml

.phive/phars.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<phive xmlns="https://phar.io/phive">
33
<phar name="phpcbf" version="^3.6.0" location="./.phive/phpcbf.phar" copy="false" installed="3.6.0"/>
44
<phar name="phpcs" version="^3.6.0" location="./.phive/phpcs.phar" copy="false" installed="3.6.0"/>
5+
<phar name="phpstan" version="^0.12.88" installed="0.12.88" location="./.phive/phpstan.phar" copy="false"/>
56
</phive>

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
"@ci:static"
2424
],
2525
"ci:php:sniff": "@php ./.phive/phpcs.phar lib tests",
26+
"ci:php:stan": "@php ./.phive/phpstan.phar",
2627
"ci:static": [
27-
"@ci:php:sniff"
28+
"@ci:php:sniff",
29+
"@ci:php:stan"
2830
],
2931
"fix:php": [
3032
"@fix:php:sniff"
3133
],
32-
"fix:php:sniff": "@php ./.phive/phpcbf.phar lib tests"
34+
"fix:php:sniff": "@php ./.phive/phpcbf.phar lib tests",
35+
"phpstan:baseline": "@php ./.phive/phpstan.phar --generate-baseline"
3336
}
3437
}

phpstan-baseline.neon

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Class Sabberworm\\\\CSS\\\\Parsing\\\\ParserState constructor invoked with 1 parameter, 2\\-3 required\\.$#"
5+
count: 1
6+
path: lib/Sabberworm/CSS/CSSList/CSSList.php
7+
8+
-
9+
message: "#^Access to an undefined property Sabberworm\\\\CSS\\\\Parsing\\\\ParserState\\:\\:\\$oParserHelper\\.$#"
10+
count: 1
11+
path: lib/Sabberworm/CSS/Parsing/ParserState.php
12+
13+
-
14+
message: "#^Access to an undefined property Sabberworm\\\\CSS\\\\Property\\\\Charset\\:\\:\\$aComments\\.$#"
15+
count: 5
16+
path: lib/Sabberworm/CSS/Property/Charset.php
17+
18+
-
19+
message: "#^Class PHPUnit\\\\Framework\\\\TestCase referenced with incorrect case\\: PHPunit\\\\Framework\\\\TestCase\\.$#"
20+
count: 1
21+
path: tests/Sabberworm/CSS/OutputFormatTest.php
22+
23+
-
24+
message: "#^Class PHPUnit\\\\Framework\\\\TestCase referenced with incorrect case\\: PHPunit\\\\Framework\\\\TestCase\\.$#"
25+
count: 1
26+
path: tests/Sabberworm/CSS/ParserTest.php
27+

phpstan.neon.dist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
parallel:
6+
# Don't be overly greedy on machines with more CPU's to be a good neighbor especially on CI
7+
maximumNumberOfProcesses: 5
8+
9+
level: 0
10+
11+
scanDirectories:
12+
- %currentWorkingDirectory%/lib/
13+
- %currentWorkingDirectory%/tests/
14+
paths:
15+
- %currentWorkingDirectory%/lib/
16+
- %currentWorkingDirectory%/tests/

0 commit comments

Comments
 (0)