Skip to content

Commit 4865fa1

Browse files
authored
Merge pull request #258 from wp-cli/203-add-phpstan
2 parents 2b45c1d + a96a80b commit 4865fa1

12 files changed

+554
-190
lines changed

bin/run-phpstan-tests

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Run the code style check only if a configuration file exists.
4+
if [ -f "phpstan.dist.neon" ] || [ -f "phpstan.neon.dist" ] || [ -f "phpstan.neon" ]
5+
then
6+
vendor/bin/phpstan --memory-limit=2048M analyse "$@"
7+
fi

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"php-parallel-lint/php-console-highlighter": "^1.0",
1616
"php-parallel-lint/php-parallel-lint": "^1.3.1",
1717
"phpcompatibility/php-compatibility": "dev-develop",
18+
"phpstan/extension-installer": "^1.4.3",
19+
"phpstan/phpstan": "^1.12.26",
20+
"szepeviktor/phpstan-wordpress": "^v1.3.5",
1821
"wp-cli/config-command": "^1 || ^2",
1922
"wp-cli/core-command": "^1 || ^2",
2023
"wp-cli/eval-command": "^1 || ^2",
@@ -28,7 +31,8 @@
2831
"config": {
2932
"allow-plugins": {
3033
"dealerdirect/phpcodesniffer-composer-installer": true,
31-
"johnpbloch/wordpress-core-installer": true
34+
"johnpbloch/wordpress-core-installer": true,
35+
"phpstan/extension-installer": true
3236
},
3337
"sort-packages": true,
3438
"lock": false
@@ -63,19 +67,22 @@
6367
"bin/run-linter-tests",
6468
"bin/run-php-unit-tests",
6569
"bin/run-phpcs-tests",
66-
"bin/run-phpcbf-cleanup"
70+
"bin/run-phpcbf-cleanup",
71+
"bin/run-phpstan-tests"
6772
],
6873
"scripts": {
6974
"behat": "run-behat-tests",
7075
"behat-rerun": "rerun-behat-tests",
7176
"lint": "run-linter-tests",
7277
"phpcs": "run-phpcs-tests",
7378
"phpcbf": "run-phpcbf-cleanup",
79+
"phpstan": "run-phpstan-tests",
7480
"phpunit": "run-php-unit-tests",
7581
"prepare-tests": "install-package-tests",
7682
"test": [
7783
"@lint",
7884
"@phpcs",
85+
"@phpstan",
7986
"@phpunit",
8087
"@behat"
8188
]

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#############################################################################
6060
-->
6161

62+
<exclude-pattern>tests/phpstan/scan-files.php</exclude-pattern>
63+
6264
<!-- This is a procedural stand-alone file that is never loaded in a WordPress context,
6365
so this file does not have to comply with WP naming conventions. -->
6466
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">

phpstan.neon.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
- tests
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli
8+
- vendor/phpunit/php-code-coverage
9+
- vendor/behat/behat
10+
scanFiles:
11+
- tests/phpstan/scan-files.php
12+
treatPhpDocTypesAsCertain: false
13+
dynamicConstantNames:
14+
- WP_DEBUG
15+
- WP_DEBUG_LOG
16+
- WP_DEBUG_DISPLAY
17+
ignoreErrors:
18+
# Needs fixing in WP-CLI.
19+
- message: '#Parameter \#1 \$cmd of function WP_CLI\\Utils\\esc_cmd expects array<string>#'

0 commit comments

Comments
 (0)