-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Tests / Build Scripts: Configure PHPStan levels 1-6 [Exploratory] #7619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justlevine
wants to merge
118
commits into
WordPress:trunk
Choose a base branch
from
justlevine:feat/phpstan
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,710
−2
Open
Changes from all commits
Commits
Show all changes
118 commits
Select commit
Hold shift + click to select a range
f7902b2
tests: configure PHPStan
justlevine 805199c
chore: update config
justlevine 5aad07a
tests: exclude `wp-include/blocks` from PHPStan analysis
justlevine cc24e27
chore: remove `-v` flag from `analyse` composer command
justlevine c2da5b6
tests: regenerate PHPStan baselines after rebase
justlevine 8fd0517
tests: exclude additional external libraries to match phpcs.xml.dist
justlevine cdc3c6d
tmp: bump PHPStan to 2.x
justlevine 9bb36a4
chore: regenerate PHPStan Baselines after rebase
justlevine 6744b39
tests: suppress errors when string is used as `callable`
justlevine 64d5311
chore: regenerate PHPStan Baselines after rebase
justlevine 3746454
chore: regenerate PHPStan baselines after rebase
justlevine da39d35
dev: revert PHPStan to v1.x
justlevine 52375af
ci: add GH workflow for PHPStan
justlevine 004f70a
chore: regenerate PHPStan baselines after rebase
justlevine 44c3beb
ci: use verbose PHPStan debugging
justlevine 8a3775f
chore: regenerate PHPStan baselines after rebase
justlevine 6589ce9
tests: define PHPStan `dynamicConstantNames`
justlevine c2acb6e
tests: Ignore `missingType.return` PHPStan error until `: void` types…
justlevine 44a62c0
chore: regenerate PHPStan baselines
justlevine 0e2d031
tests: set PHPStan `treatPhpDocTypesAsCertain` to false
justlevine d949a94
chore: regenerate PHPStan baselines
justlevine c92201e
chore: regenerate PHPStan baselines
justlevine d6d59a0
tests: Don't stan deprecated `wp-tinymce.php`
justlevine 3a7f4d4
chore: regenerate PHPStan baselines
justlevine 06f7f92
PHPStan: define additional dynamic constants
justlevine 9ca376e
PHPStan: additional dynamicConstantNames
justlevine 50169b6
chore: regenerate PHPStan baselines
justlevine fb61258
chore: regenerate PHPStan baselines
justlevine 174afe0
PHPStan: limit memory usage when running `composer analyse`
justlevine c8645e8
chore: regenerate PHPStan baselines
justlevine fe5882a
tests: bump PHPStan to v2.x
justlevine 5f43db2
chore: regenerate PHPStan baselines
justlevine 0840486
chore: regenerate baselines
justlevine 8a152d3
Remove some testing on < 7.4.
johnbillion 9125d57
chore: use tabs for `.neon` and update annotation tenses
justlevine 94fca70
PHPStan: restore and baseline inner function smells.
justlevine 87e966a
ci: rename job + fix version targeting
justlevine 1c9cfb9
PHPStan: clarify `dynamicConstantNames`
justlevine c43413f
chore: regenerate baselines
justlevine 7e71c2f
chore: fix mixed tabs/spaces
justlevine 0069fc5
chore: fix typo in phpstan.neon
justlevine d5a10d2
chore: regenerate baselines
justlevine f6af340
chore: bump phpstan to minimum 2.1.19 (bugfix)
justlevine 46d4e72
phpstan: regenerate baselines
justlevine 760d701
phpstan: regenerate baselines after rebase
justlevine 9680162
phpstan: regenerate baselines after rebase
justlevine 2839f28
phpstan: bump max PHP version to check to 80500
justlevine a4ee081
phpstan: remove unnecessary `WP_CONTENT_DIR` from bootstrap
justlevine 6e2aa00
phpstan: ignore `wp-includes.user`
justlevine 020f347
phpstan: update excludePaths
justlevine 9f09845
phpstan: regenerate baselines
justlevine 86c9442
tests: phpstan level 0
justlevine e50b2dc
Merge branch 'tests/phpstan/level-0' into feat/phpstan
justlevine 8ea09de
chore: post-merge cleanup
justlevine 0308f9e
tests: phpstan level 0
justlevine 5ccfa1c
Merge branch 'tests/phpstan/level-0' into feat/phpstan
justlevine 79b737b
chore: regenerate baselines
justlevine e169af4
Merge branch 'trunk' into feat/phpstan
justlevine b427ca6
Merge branch 'trunk' into tests/phpstan/level-0
justlevine a741131
chore: phpstan v2 and post merge cleanup
justlevine 88c5426
chore: cleanup readme
justlevine 03b4080
tests: remove unnecessary @phpstan-ignore
justlevine cd1149a
docs: add `never|void` return type to `wp_die()`
justlevine aec7e74
ci: run `build:dev`
justlevine acfeb8d
Merge branch 'trunk' into tests/phpstan/level-0
westonruter d429181
Update src/wp-includes/functions.php
justlevine de6d304
Update tests/phpstan/bootstrap.php
justlevine d43edb1
Update tests/phpstan/README.md
justlevine 8e5e8b0
Update .github/workflows/php-static-analysis.yml
justlevine 75c8c54
Merge branch 'trunk' into tests/phpstan/level-0
justlevine 4c255e5
PHPStan: Use explicit paths to avoid hanging on wp-content traversal
westonruter 522147a
Remove excludePaths for non-PHP directories since files already excluded
westonruter f77df14
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter baf4516
Address issues with class-wp-html-processor.php which required it to …
westonruter 1603823
Fix return types for core themes
westonruter 367af1c
Add variable return type for WP_Theme::get()
westonruter ae6c4b6
Ensure Customizer setting exists before setting transport to postMessage
westonruter 9d178c6
Pass empty strings instead of null in twenty_twenty_one_generate_css()
westonruter b1005dc
Ensure Twenty_Twenty_One_SVG_Icons::get_svg() always returns string v…
westonruter f95668e
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 2f72407
Fix return types for Customize setting update methods
westonruter 22370b6
Update return value for WP_Customize_Background_Image_Setting::update()
westonruter 199f15f
Use phpstan as composer script name
westonruter ec446a1
Update phpstan as script name in docs
westonruter 420731d
Rename test:php:stan to typecheck:php
westonruter e0398cd
Declare 7.0.0 as the verison which introduced PHPStan
westonruter 8132f48
Fix paths in readme
westonruter 9ebcf81
Use US spelling of 'analyze' for consistency with the rest of the cod…
westonruter c87e560
Add baseline.php to list of files which triggers the workflow
westonruter ee31281
Fix grammar typo in readme
westonruter 1c1cb16
Use same version of actions/cache as rest of codebase
westonruter cc01268
CI: Optimize PHP Static Analysis by caching Gutenberg build
westonruter 77d9403
Improve placement and formatting of phpstan-return
westonruter 61f8a11
Fix wp_insert_user() so PHPStan won't hang
westonruter fd8f672
Fix handling of ArrayAccess since PHPStan still would hang
westonruter 512e368
Revert now-unnecessary change since $userdata is always an array
westonruter dd0727f
Update tests/phpunit/tests/user.php
justlevine dada996
Add assertion for warning
westonruter b883096
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 646edd0
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 03b9766
Update package.json
justlevine 7b9c9b1
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 935e7e2
Replace phpstan-ignore-next-line comment with returning false
westonruter 34d5a05
Add isset.variable error suppression for extracted var
westonruter 4513d92
CI: Report PHPStan errors as warnings in reusable workflow
westonruter 6a46b90
Build: Add phpstan task and include it in precommit:php
westonruter 18ecd38
Disable reportUnmatchedIgnoredErrors to allow ignoring errors for str…
westonruter 6d7f578
Revert reportUnmatchedIgnoredErrors and ignoring isset.variable in fa…
westonruter 05a968f
Invoke PHPStan via composer and remove phpstan-ignore comment to test
westonruter f3990da
Restore phpstan-ignore comment
westonruter 57d6d90
Remove Gutenberg cache for initial commit
westonruter 4486d82
Rename workflows to be specific for PHPStan
westonruter 88d619b
Pin phpstan at latest version
westonruter 2a1c830
Merge branch 'trunk' into tests/phpstan/level-0
westonruter 12dc127
Remove redundant paths in scanDirectories
westonruter 83246de
Fix return description for wp_die()
westonruter 5cb43a0
Merge branch 'tests/phpstan/level-0' of https://github.com/justlevine…
westonruter 05da415
Merge branch 'trunk' into feat/phpstan
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,17 @@ includes: | |
|
|
||
| # The baseline file includes preexisting errors in the codebase that should be ignored. | ||
| # https://phpstan.org/user-guide/baseline | ||
| - tests/phpstan/baseline.php | ||
| - tests/phpstan/baseline.php # level 0. | ||
| - tests/phpstan/baseline/level-1.php | ||
| - tests/phpstan/baseline/level-2.php | ||
| - tests/phpstan/baseline/level-3.php | ||
| - tests/phpstan/baseline/level-4.php | ||
| - tests/phpstan/baseline/level-5.php | ||
| - tests/phpstan/baseline/level-6.php | ||
|
|
||
| parameters: | ||
| # https://phpstan.org/user-guide/rule-levels | ||
| level: 0 | ||
| level: 6 | ||
| reportUnmatchedIgnoredErrors: true | ||
|
|
||
| ignoreErrors: | ||
|
|
@@ -34,3 +40,17 @@ parameters: | |
| identifier: function.inner | ||
| path: src/wp-includes/canonical.php | ||
| count: 1 | ||
|
|
||
| # Level 1: | ||
| - # These are too noisy at the moment. | ||
| message: '#Variable \$[a-zA-Z0-9_]+ might not be defined\.#' | ||
|
|
||
| # Level 2: | ||
| - # Callable-strings are used as callables in WordPress. | ||
| message: '#Default value of the parameter .* is incompatible with type callable.*#' | ||
|
|
||
| # Level 6: | ||
| - # WPCS syntax for iterable types is not supported. | ||
| identifier: missingType.iterableValue | ||
| - # Too noisy until `void` return types are allowed. | ||
| identifier: missingType.return | ||
|
Comment on lines
+55
to
+56
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now allowed! |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| $ignoreErrors = []; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Call to function compact\\(\\) contains possibly undefined variable \\$comment_author\\.$#', | ||
| 'identifier' => 'variable.undefined', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/ajax-actions.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Call to function compact\\(\\) contains possibly undefined variable \\$comment_author_email\\.$#', | ||
| 'identifier' => 'variable.undefined', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/ajax-actions.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Call to function compact\\(\\) contains possibly undefined variable \\$comment_author_url\\.$#', | ||
| 'identifier' => 'variable.undefined', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/ajax-actions.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Call to function compact\\(\\) contains possibly undefined variable \\$user_id\\.$#', | ||
| 'identifier' => 'variable.undefined', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/ajax-actions.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$_POST in isset\\(\\) always exists and is not nullable\\.$#', | ||
| 'identifier' => 'isset.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/class-custom-image-header.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Constructor of class WP_Filesystem_Direct has an unused parameter \\$arg\\.$#', | ||
| 'identifier' => 'constructor.unusedParameter', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/class-wp-filesystem-direct.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$class in empty\\(\\) always exists and is always falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/class-wp-posts-list-table.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$_POST in isset\\(\\) always exists and is not nullable\\.$#', | ||
| 'identifier' => 'isset.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/includes/media.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$parent_file in empty\\(\\) always exists and is not falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-admin/themes.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$addl_path in empty\\(\\) always exists and is always falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/canonical.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$namespace in isset\\(\\) always exists and is not nullable\\.$#', | ||
| 'identifier' => 'isset.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/class-wp-block-parser.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$block_type in empty\\(\\) always exists and is not falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/class-wp-block-supports.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$loader in isset\\(\\) always exists and is not nullable\\.$#', | ||
| 'identifier' => 'isset.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/class-wp-oembed.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$search in empty\\(\\) always exists and is not falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/class-wp-query.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$status_type_clauses in empty\\(\\) always exists and is not falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/class-wp-query.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$modes_str in empty\\(\\) always exists and is not falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/class-wpdb.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$deprecated in empty\\(\\) always exists and is always falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/pluggable.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$schema in empty\\(\\) is never defined\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$the_parent in empty\\(\\) always exists and is not falsy\\.$#', | ||
| 'identifier' => 'empty.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/taxonomy.php', | ||
| ]; | ||
| $ignoreErrors[] = [ | ||
| 'message' => '#^Variable \\$s in isset\\(\\) is never defined\\.$#', | ||
| 'identifier' => 'isset.variable', | ||
| 'count' => 1, | ||
| 'path' => __DIR__ . '/../../../src/wp-includes/template.php', | ||
| ]; | ||
|
|
||
| return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justlevine How were these generated? It seems
level-2.phpomits the errors from level 1? Andlevel-3.phpomits the errors from level 2, and so on? When I runcomposer phpstan -- --level=3 --generate-baseline=tests/phpstan/baseline/level-3.phpit includes errors from levels 1-3.