Skip to content

Commit 10529ca

Browse files
committed
introduce PHPStan static code analysis (#45)
Add PHPStan and WP stubs to our dev-dependencies and configure a CI workflow to run the analysis. We can start at level 3 without any additional code changes required.
1 parent 89af04c commit 10529ca

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

.distignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
/package.json
1616
/package-lock.json
1717
/phpcs.xml
18+
/phpstan.neon
1819
/phpunit.xml

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ composer.lock export-ignore
1111
CONTRIBUTING.md export-ignore
1212
package.json export-ignore
1313
phpcs.xml export-ignore
14+
phpstan.neon export-ignore
1415
phpunit.xml export-ignore

.github/workflows/phpstan.yml

Whitespace-only changes.

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,20 @@ jobs:
5353
run: composer install --no-interaction
5454
- name: Code style checks for PHP
5555
run: composer test-cs
56+
57+
phpstan:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v5
62+
with:
63+
fetch-depth: 0
64+
- name: Setup PHP
65+
uses: shivammathur/setup-php@v2
66+
with:
67+
php-version: 8.4
68+
tools: composer
69+
- name: Install PHP dependencies
70+
run: composer install --no-interaction --prefer-dist --no-scripts
71+
- name: PHPStan
72+
run: composer phpstan

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"phpunit/phpunit": "^8|^9",
2727
"slowprog/composer-copy-file": "~0.3",
2828
"squizlabs/php_codesniffer": "^3.13",
29+
"szepeviktor/phpstan-wordpress": "^v2.0",
30+
"phpstan/extension-installer": "^1.4",
31+
"phpstan/phpstan": "^2.1",
2932
"phpcompatibility/phpcompatibility-wp": "^2.1",
3033
"wp-coding-standards/wpcs": "^3.2"
3134
},
@@ -47,7 +50,8 @@
4750
"config": {
4851
"allow-plugins": {
4952
"composer/installers": true,
50-
"dealerdirect/phpcodesniffer-composer-installer": true
53+
"dealerdirect/phpcodesniffer-composer-installer": true,
54+
"phpstan/extension-installer": true
5155
}
5256
}
5357
}

phpstan.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
level: 3
3+
paths:
4+
- inc/
5+
- statify-blacklist.php
6+
ignoreErrors:
7+
- message: '/^Constant STATIFYBLACKLIST_BASE not found\.$/'
8+
path: inc/

0 commit comments

Comments
 (0)