Skip to content

Commit 4392745

Browse files
committed
tests: configure PHPStan
1 parent 6996faa commit 4392745

14 files changed

Lines changed: 24345 additions & 1 deletion

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ insert_final_newline = true
1313
trim_trailing_whitespace = true
1414
indent_style = tab
1515

16-
[*.yml]
16+
[{*.yml,*.neon,*.neon.dist}]
1717
indent_style = space
1818
indent_size = 2
1919

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ wp-tests-config.php
2222
/build
2323
/tests/phpunit/build
2424
/wp-cli.local.yml
25+
/phpstan.neon
2526
/jsdoc
2627
/composer.lock
2728
/vendor

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"squizlabs/php_codesniffer": "3.10.3",
2121
"wp-coding-standards/wpcs": "~3.1.0",
2222
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
23+
"phpstan/phpstan": "1.12.7",
2324
"yoast/phpunit-polyfills": "^1.1.0"
2425
},
2526
"config": {
@@ -29,6 +30,7 @@
2930
"lock": false
3031
},
3132
"scripts": {
33+
"analyse": "@php ./vendor/bin/phpstan analyse -v",
3234
"compat": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --standard=phpcompat.xml.dist --report=summary,source",
3335
"format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source",
3436
"lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source",

phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
<exclude-pattern>/tests/phpunit/build*</exclude-pattern>
8282
<exclude-pattern>/tests/phpunit/data/*</exclude-pattern>
8383

84+
<!-- PHPStan bootstrap, stubs, and baseline. -->
85+
<exclude-pattern>/tests/phpstan/*</exclude-pattern>
86+
8487
<exclude-pattern>/tools/*</exclude-pattern>
8588

8689
<!-- Drop-in plugins. -->

phpstan.neon.dist

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# PHPStan configuration for WordPress Core.
2+
#
3+
# To overload this configuration, copy this file to phpstan.neon and adjust as needed.
4+
#
5+
# https://phpstan.org/config-reference
6+
7+
includes:
8+
# The WordPress Core configuration file includes the base configuration for the WordPress codebase.
9+
- tests/phpstan/base.neon
10+
# The baseline file includes preexisting errors in the codebase that should be ignored.
11+
# https://phpstan.org/user-guide/baseline
12+
- tests/phpstan/baseline/level-0.php
13+
- tests/phpstan/baseline/level-1.php
14+
- tests/phpstan/baseline/level-2.php
15+
- tests/phpstan/baseline/level-3.php
16+
- tests/phpstan/baseline/level-4.php
17+
- tests/phpstan/baseline/level-5.php
18+
- tests/phpstan/baseline/level-6.php
19+
20+
parameters:
21+
level: 6
22+
23+
ignoreErrors:
24+
# Inner functions aren't supported:
25+
- '#Inner named functions are not supported by PHPStan#'
26+
# Inner functions within the importer:
27+
- '#Function wxr_[a-z_]+ not found#'
28+
29+
# Level 1:
30+
31+
# These are too noisy at the moment:
32+
- '#Variable \$[a-zA-Z0-9_]+ might not be defined\.#'
33+
- '#Variable \$[a-zA-Z0-9_]+ in isset\(\) always exists and is not nullable\.#'
34+
35+
# Level 6:
36+
37+
# WPCS syntax for iterable types is not supported:
38+
-
39+
identifier: missingType.iterableValue

tests/phpstan/base.neon

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Base PHPStan configuration for WordPress Core.
2+
#
3+
# This is kept separate from the main PHPStan configuration file to allow for easy overloading while baseline errors are being fixed.
4+
#
5+
# https://phpstan.org/config-reference
6+
7+
parameters:
8+
# What directories and files should be scanned.
9+
paths:
10+
- ../../src
11+
bootstrapFiles:
12+
- bootstrap.php
13+
scanFiles:
14+
- ../../wp-config-sample.php
15+
- ../../src/wp-admin/includes/ms.php
16+
scanDirectories:
17+
- ../../src/wp-includes
18+
- ../../src/wp-admin
19+
excludePaths:
20+
analyseAndScan:
21+
# These files are deprecated and should not be scanned.
22+
- ../../src/wp-admin/includes/deprecated.php
23+
- ../../src/wp-admin/includes/ms-deprecated.php
24+
- ../../src/wp-admin/includes/noop.php
25+
- ../../src/wp-includes/deprecated.php
26+
- ../../src/wp-includes/ms-deprecated.php
27+
- ../../src/wp-includes/pluggable-deprecated.php
28+
# These files are not part of the WordPress Core codebase.
29+
- ../../src/wp-content
30+
# JavaScript/CSS/Asset files.
31+
- ../../src/js
32+
- ../../src/wp-admin/css
33+
- ../../src/wp-admin/images
34+
- ../../src/wp-admin/js
35+
analyse:
36+
# Third-party libraries.
37+
- ../../src/wp-admin/includes/class-ftp-pure.php
38+
- ../../src/wp-admin/includes/class-ftp-sockets.php
39+
- ../../src/wp-admin/includes/class-ftp.php
40+
- ../../src/wp-admin/includes/class-pclzip.php
41+
- ../../src/wp-includes/atomlib.php
42+
- ../../src/wp-includes/class-json.php
43+
- ../../src/wp-includes/class-phpmailer.php
44+
- ../../src/wp-includes/class-requests.php
45+
- ../../src/wp-includes/class-simplepie.php
46+
- ../../src/wp-includes/class-smtp.php
47+
- ../../src/wp-includes/class-snoopy.php
48+
- ../../src/wp-includes/class-wp-feed-cache.php
49+
- ../../src/wp-includes/class-wp-http-ixr-client.php
50+
- ../../src/wp-includes/class-wp-http-requests-hooks.php
51+
- ../../src/wp-includes/class-wp-http-requests-response.php
52+
- ../../src/wp-includes/class-wp-simplepie-file.php
53+
- ../../src/wp-includes/class-wp-simplepie-sanitize-kses.php
54+
- ../../src/wp-includes/class-wp-text-diff-renderer-inline.php
55+
- ../../src/wp-includes/class-wp-text-diff-renderer-table.php
56+
- ../../src/wp-includes/ID3
57+
- ../../src/wp-includes/PHPMailer
58+
- ../../src/wp-includes/pomo
59+
- ../../src/wp-includes/random_compat
60+
- ../../src/wp-includes/Requests
61+
- ../../src/wp-includes/rss.php
62+
- ../../src/wp-includes/SimplePie
63+
- ../../src/wp-includes/sodium_compat
64+
- ../../src/wp-includes/Text
65+
# Contains errors that cannot be ignored by PHPStan.
66+
- ../../src/wp-includes/html-api/class-wp-html-processor.php

0 commit comments

Comments
 (0)