-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Tools: Add and configure PHPStan static analysis #66693
Draft
justlevine
wants to merge
1
commit into
WordPress:trunk
Choose a base branch
from
justlevine:tools/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.
+2,723
−2
Draft
Changes from all commits
Commits
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 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
This file contains 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
This file contains 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
This file contains 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,34 @@ | ||
# PHPStan configuration for Gutenberg | ||
# | ||
# To overload this configuration, copy this file to phpstan.neon and adjust as needed. | ||
# | ||
# https://phpstan.org/config-reference | ||
|
||
includes: | ||
# The WordPress Core configuration file includes the base configuration for the WordPress codebase. | ||
- tools/phpstan/base.neon | ||
# The baseline file includes preexisting errors in the codebase that should be ignored. | ||
# https://phpstan.org/user-guide/baseline | ||
- tools/phpstan/baseline/level-0.php | ||
- tools/phpstan/baseline/level-1.php | ||
- tools/phpstan/baseline/level-2.php | ||
- tools/phpstan/baseline/level-3.php | ||
- tools/phpstan/baseline/level-4.php | ||
- tools/phpstan/baseline/level-5.php | ||
- tools/phpstan/baseline/level-6.php | ||
- tools/phpstan/baseline/level-7.php | ||
|
||
parameters: | ||
level: 7 | ||
|
||
treatPhpDocTypesAsCertain: false | ||
|
||
ignoreErrors: | ||
# @TODO: need to discover these symbols. | ||
- '#Function gutenberg_.* not found.#' | ||
|
||
# Level 6: | ||
|
||
# WPCS syntax for iterable types is not supported: | ||
- | ||
identifier: missingType.iterableValue |
This file contains 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,26 @@ | ||
# Base PHPStan configuration for Gutenberg | ||
# | ||
# This is kept separate from the main PHPStan configuration file to allow for easy overloading while baseline errors are being fixed. | ||
# | ||
# https://phpstan.org/config-reference | ||
|
||
parameters: | ||
# What directories and files should be scanned. | ||
paths: | ||
- ../../gutenberg.php | ||
- ../../post-content.php | ||
- ../../lib | ||
bootstrapFiles: | ||
- bootstrap.php | ||
- ../../gutenberg.php | ||
scanFiles: | ||
- ../../gutenberg.php | ||
- ../../post-content.php | ||
scanDirectories: | ||
- ../../lib | ||
- ../../packages | ||
excludePaths: | ||
analyse: | ||
# Exclude files maintained in WordPress Core and backported to Gutenberg. | ||
- ../../lib/compat/wordpress-*/html-api/* | ||
- ../../packages/block-serialization-spec-parser/parser |
This file contains 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,65 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
$ignoreErrors = []; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Callback expects 1 parameter, \\$accepted_args is set to 2\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/block-supports/block-style-variations.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: return.missing | ||
'message' => '#^Function gutenberg_tinycolor_string_to_rgb\\(\\) should return array but return statement is missing\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/block-supports/duotone.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: return.missing | ||
'message' => '#^Method WP_Duotone_Gutenberg\\:\\:get_selector\\(\\) should return string but return statement is missing\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/class-wp-duotone-gutenberg.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: return.missing | ||
'message' => '#^Method WP_Theme_JSON_Gutenberg\\:\\:should_override_preset\\(\\) should return bool but return statement is missing\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/class-wp-theme-json-gutenberg.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: phpDoc.parseError | ||
'message' => '#^One or more @param tags has an invalid name or invalid syntax\\.$#', | ||
'count' => 4, | ||
'path' => __DIR__ . '/../../../lib/class-wp-theme-json-resolver-gutenberg.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: class.notFound | ||
'message' => '#^Call to static method get_stores\\(\\) on an unknown class WP_Style_Engine_CSS_Rules_Store_Gutenberg\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/client-assets.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: new.static | ||
'message' => '#^Unsafe usage of new static\\(\\)\\.$#', | ||
'count' => 2, | ||
'path' => __DIR__ . '/../../../lib/compat/wordpress-6.6/class-gutenberg-token-map-6-6.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: return.missing | ||
'message' => '#^Method Gutenberg_REST_Templates_Controller_6_7\\:\\:get_wp_templates_author_text_field\\(\\) should return string but return statement is missing\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/compat/wordpress-6.7/class-gutenberg-rest-templates-controller-6-7.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Callback expects 1 parameter, \\$accepted_args is set to 2\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/experimental/kses-allowed-html.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Callback expects 1 parameter, \\$accepted_args is set to 2\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/rest-api.php', | ||
]; | ||
|
||
return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; |
This file contains 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,59 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
$ignoreErrors = []; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Function remove_filter invoked with 4 parameters, 2\\-3 required\\.$#', | ||
'count' => 4, | ||
'path' => __DIR__ . '/../../../lib/block-supports/elements.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Function remove_filter invoked with 4 parameters, 2\\-3 required\\.$#', | ||
'count' => 3, | ||
'path' => __DIR__ . '/../../../lib/block-supports/layout.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Function remove_filter invoked with 4 parameters, 2\\-3 required\\.$#', | ||
'count' => 2, | ||
'path' => __DIR__ . '/../../../lib/block-supports/settings.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: variable.undefined | ||
'message' => '#^Variable \\$filter_id might not be defined\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/class-wp-duotone-gutenberg.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: isset.variable | ||
'message' => '#^Variable \\$area in isset\\(\\) always exists and is not nullable\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/compat/wordpress-6.6/block-template-utils.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Class WP_Webfonts constructor invoked with 1 parameter, 0 required\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/experimental/font-face/bc-layer/webfonts-deprecations.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: arguments.count | ||
'message' => '#^Function gutenberg_url invoked with 2 parameters, 1 required\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/experimental/posts/load.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: variable.undefined | ||
'message' => '#^Variable \\$cache_key might not be defined\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/global-styles-and-settings.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
// identifier: variable.undefined | ||
'message' => '#^Variable \\$cached might not be defined\\.$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../../../lib/global-styles-and-settings.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.
E.g.
gutenberg_style_engine_get_styles()
. Only thing close I could find waswp_style_engine_get_styles()
inpackages/style-engine
.Is there some aliasing or build step search-replace that happens? Am I missing a path in
base.neon
, or do we need to alias/stub these functions ourselves?