Skip to content

Commit 1c4578c

Browse files
Merge pull request #1063 from Codeinwp/dev/phpstan
dev: add PHPStan
2 parents 1b104fd + ff46622 commit 1c4578c

File tree

7 files changed

+5610
-60
lines changed

7 files changed

+5610
-60
lines changed

.distignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ vue
3131
.stylelintrc
3232
webpack.config.js
3333
docker-compose.yml
34+
phpstan.neon
35+
phpstan-baseline.neon

.github/workflows/test-php.yml

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,26 @@ concurrency:
66
on:
77
push:
88
branches-ignore:
9-
- 'master'
9+
- "master"
1010

1111
jobs:
1212
code-sniff:
1313
name: PHP Lint
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Checkout source code
17-
uses: actions/checkout@v2
18-
- name: Setup PHP
19-
uses: shivammathur/setup-php@v2
20-
with:
21-
php-version: '7.4'
16+
- name: Checkout source code
17+
uses: actions/checkout@v4
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: "7.4"
2222
tools: phpcs, phpcbf
23-
- name: Get Composer Cache Directory
24-
id: composer-cache
25-
run: |
26-
echo "::set-output name=dir::$(composer config cache-files-dir)"
27-
- name: Setup Composer cache
28-
uses: actions/cache@v4
29-
with:
30-
path: ${{ steps.composer-cache.outputs.dir }}
31-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
32-
restore-keys: |
33-
${{ runner.os }}-composer-
34-
- name: Run Composer Install
35-
run: composer install --prefer-dist --no-progress --quiet
36-
continue-on-error: true
37-
- name: Run PHPCS
38-
run: composer run lint
39-
continue-on-error: false
40-
23+
- name: Run Composer Install
24+
run: composer install --prefer-dist --no-progress --quiet
25+
continue-on-error: true
26+
- name: Run PHPCS
27+
run: composer run lint
28+
continue-on-error: false
4129

4230
php-unit:
4331
name: PHPUnit
@@ -49,30 +37,36 @@ jobs:
4937
env:
5038
MYSQL_ROOT_PASSWORD: root
5139
ports:
52-
- 3306/tcp
40+
- 3306/tcp
5341
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
5442
steps:
55-
- name: Checkout source code
56-
uses: actions/checkout@v2
57-
- name: Setup PHP
58-
uses: shivammathur/setup-php@v2
59-
with:
60-
php-version: '7.4'
43+
- name: Checkout source code
44+
uses: actions/checkout@v4
45+
- name: Setup PHP
46+
uses: shivammathur/setup-php@v2
47+
with:
48+
php-version: "7.4"
6149
tools: phpunit-polyfills
62-
- name: Install WordPress Test Suite
63-
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
64-
- name: Get Composer Cache Directory
65-
id: composer-cache
66-
run: |
67-
echo "::set-output name=dir::$(composer config cache-files-dir)"
68-
- name: Setup Composer cache
69-
uses: actions/cache@v4
70-
with:
71-
path: ${{ steps.composer-cache.outputs.dir }}
72-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
73-
restore-keys: |
74-
${{ runner.os }}-composer-
75-
- name: Install composer
76-
run: composer install --prefer-dist --no-progress
77-
- name: Run PHP Unit
78-
run: composer run test
50+
- name: Install WordPress Test Suite
51+
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }}
52+
- name: Install composer
53+
run: composer install --prefer-dist --no-progress
54+
- name: Run PHP Unit
55+
run: composer run test
56+
57+
phpstan:
58+
name: PHPStan
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Setup PHP version
62+
uses: shivammathur/setup-php@v2
63+
with:
64+
php-version: "7.4"
65+
extensions: simplexml
66+
- name: Checkout source code
67+
uses: actions/checkout@v4
68+
- name: Install composer
69+
run: |
70+
composer install --prefer-dist --no-progress
71+
- name: Run phpstan
72+
run: composer run phpstan

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"build": "sh bin/dist.sh",
2424
"test": "vendor/bin/phpunit",
2525
"lint": "vendor/bin/phpcs --standard=phpcs.xml --extensions=php -s",
26-
"format": "vendor/bin/phpcbf --standard=phpcs.xml --report-summary --report-source"
26+
"format": "vendor/bin/phpcbf --standard=phpcs.xml --report-summary --report-source",
27+
"phpstan": "phpstan",
28+
"phpstan:generate:baseline": "phpstan --generate-baseline"
2729
},
2830
"autoload": {
2931
"files": [
@@ -54,7 +56,9 @@
5456
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
5557
"phpunit/phpunit": "9.*",
5658
"yoast/phpunit-polyfills": "^2.0",
57-
"codeinwp/phpcs-ruleset": "dev-main"
59+
"codeinwp/phpcs-ruleset": "dev-main",
60+
"phpstan/phpstan": "^2.1",
61+
"szepeviktor/phpstan-wordpress": "^2.0"
5862
},
5963
"config": {
6064
"allow-plugins": {

composer.lock

Lines changed: 180 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)