Skip to content
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6d83596
Ignore errors in src/wp-includes/build which currently come the Guten…
westonruter Feb 25, 2026
5dec036
Bump phpstan to 2.1.40
westonruter Feb 25, 2026
593a10c
Bump PHPStan to level 1
westonruter Mar 4, 2026
22de4b6
Ignore variable.undefined errors since too noisy
westonruter Mar 4, 2026
cb8db15
Regenerate baseline for level 1
westonruter Mar 4, 2026
d3dd8ec
Remove unused parameter for WP_Filesystem_Direct constructor
westonruter Mar 4, 2026
bf92684
Add theme constants to config to address constant.notFound errors
westonruter Mar 4, 2026
d39600a
Docs: Add `@return never` to `dead_db()`.
apermo Feb 24, 2026
75797b7
fix(phpstan): Ignore return.never on dead_db()
apermo Feb 24, 2026
e55878c
Fix phpstan-return syntax
westonruter Feb 24, 2026
46b656a
Remove now-unnecessary phpstan-ignore
westonruter Feb 24, 2026
3c46095
docs: Refine phpdoc of dead_db()
apermo Feb 25, 2026
c52438a
Remove never from check_connection return
westonruter Mar 4, 2026
87a2c04
Remove errors from baseline which were fixed by never returns
westonruter Mar 4, 2026
95ddce2
Resolve isset.variable error since $_POST global is always set
westonruter Mar 4, 2026
5e62661
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Mar 6, 2026
2d77448
Use allow-list for unknown globals
westonruter Mar 6, 2026
eeefc04
Convert single variable.undefined ignore rule into one per variable
westonruter Mar 6, 2026
cb7a8c3
Remove unused $class variable after r54215 (56bde67811f432764d2be6c5c…
westonruter Mar 6, 2026
a47a434
Fix wp_cache_switch_to_blog() issues
westonruter Mar 6, 2026
680d165
Fix arguments.count issues in Twenty Seventeen where twentyseventeen_…
westonruter Mar 6, 2026
53208cc
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Mar 7, 2026
a088867
Remove $comment_id variable.undefined error after r61859 (ce40cd36)
westonruter Mar 7, 2026
202c39c
Remove $shape from being a variable.undefined ignored error
westonruter Mar 7, 2026
de684c6
Revert "Fix arguments.count issues in Twenty Seventeen where twentyse…
westonruter Mar 7, 2026
db38dbf
Initialize $shape variable to suppress variable.undefined error
westonruter Mar 7, 2026
385d8fe
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Mar 13, 2026
c2a9bc9
Remove errors from baseline fixed in r62000
westonruter Mar 13, 2026
e003c66
Remove empty.variable from baseline which was fixed in r61995
westonruter Mar 13, 2026
0b4ba77
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter Mar 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"squizlabs/php_codesniffer": "3.13.5",
"wp-coding-standards/wpcs": "~3.3.0",
"phpcompatibility/phpcompatibility-wp": "~2.1.3",
"phpstan/phpstan": "2.1.39",
"phpstan/phpstan": "2.1.40",
"yoast/phpunit-polyfills": "^1.1.0"
},
"config": {
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ includes:

parameters:
# https://phpstan.org/user-guide/rule-levels
level: 0
level: 1
reportUnmatchedIgnoredErrors: true

ignoreErrors:
Expand All @@ -34,3 +34,8 @@ parameters:
identifier: function.inner
path: src/wp-includes/canonical.php
count: 1

# Level 1:
- # These are too noisy at the moment.
identifier: variable.undefined
message: '#Variable \$[a-zA-Z0-9_]+ might not be defined\.#'
Comment thread
westonruter marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-custom-image-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public function step_2() {
$file = get_attached_file( $attachment_id, true );
$url = wp_get_attachment_image_src( $attachment_id, 'full' );
$url = $url[0];
} elseif ( isset( $_POST ) ) {
} else {
$data = $this->step_2_manage_upload();
$attachment_id = $data['attachment_id'];
$file = $data['file'];
Expand Down
4 changes: 1 addition & 3 deletions src/wp-admin/includes/class-wp-filesystem-direct.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
* Constructor.
*
* @since 2.5.0
*
* @param mixed $arg Not used.
*/
public function __construct( $arg ) {
public function __construct() {
$this->method = 'direct';
$this->errors = new WP_Error();
}
Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/class-wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,9 @@ public function parse_db_host( $host ) {
* @since 3.9.0
*
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
* @return bool|void True if the connection is up.
* @return bool Whether the connection is up. Exits when `$allow_bail` is true and the connection is down.
*
* @phpstan-return ( $allow_bail is true ? bool|never : bool )
*/
public function check_connection( $allow_bail = true ) {
// Check if the connection is alive.
Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3766,7 +3766,7 @@ function wp_nonce_ays( $action ) {
* }
* @return never|void Returns void if `$args['exit']` is false, otherwise exits.
*
* @phpstan-return ( $args['exit'] is false ? void : never )
* @phpstan-return ( $args is array{exit: false} ? void : never )
*/
function wp_die( $message = '', $title = '', $args = array() ) {
global $wp_query;
Expand Down Expand Up @@ -5501,6 +5501,8 @@ function wp_ob_end_flush_all() {
* @since 2.3.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @return never
*/
function dead_db() {
global $wpdb;
Expand Down
9 changes: 9 additions & 0 deletions tests/phpstan/base.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ parameters:
- ALLOW_SUBDIRECTORY_INSTALL
- AUTH_SALT
- AUTOMATIC_UPDATER_DISABLED
- BACKGROUND_COLOR
- BACKGROUND_IMAGE
- COOKIEPATH
- CUSTOM_TAGS
- DISALLOW_FILE_EDIT
- DISALLOW_UNFILTERED_HTML
- EMPTY_TRASH_DAYS
- ENFORCE_GZIP
- FORCE_SSL_LOGIN
- HEADER_IMAGE
- HEADER_IMAGE_HEIGHT
- HEADER_IMAGE_WIDTH
- HEADER_TEXTCOLOR
- MEDIA_TRASH
- MULTISITE
- NO_HEADER_TEXT
- NOBLOGREDIRECT
- SAVEQUERIES
- SCRIPT_DEBUG
Expand Down Expand Up @@ -105,6 +112,8 @@ parameters:
- ../../src/wp-includes/deprecated.php
- ../../src/wp-includes/ms-deprecated.php
- ../../src/wp-includes/pluggable-deprecated.php
# These files are currently pulled in from Gutenberg, but maybe not long-term. See <https://core.trac.wordpress.org/ticket/64393>.
- ../../src/wp-includes/build
# These files are sourced by wordpress/gutenberg in `tools/release/sync-stable-blocks.js`.
- ../../src/wp-includes/blocks
# Third-party libraries.
Expand Down
106 changes: 105 additions & 1 deletion tests/phpstan/baseline.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,107 @@
<?php declare(strict_types = 1);

return [];
$ignoreErrors = [];
$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' => '#^Function twentyseventeen_edit_link invoked with 1 parameter, 0 required\\.$#',
'identifier' => 'arguments.count',
'count' => 1,
'path' => __DIR__ . '/../../src/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php',
];
$ignoreErrors[] = [
'message' => '#^Function twentyseventeen_edit_link invoked with 1 parameter, 0 required\\.$#',
'identifier' => 'arguments.count',
'count' => 1,
'path' => __DIR__ . '/../../src/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php',
];
$ignoreErrors[] = [
'message' => '#^Function twentyseventeen_edit_link invoked with 1 parameter, 0 required\\.$#',
'identifier' => 'arguments.count',
'count' => 1,
'path' => __DIR__ . '/../../src/wp-content/themes/twentyseventeen/template-parts/page/content-page.php',
];
$ignoreErrors[] = [
'message' => '#^Function wp_cache_switch_to_blog_fallback invoked with 1 parameter, 0 required\\.$#',
'identifier' => 'arguments.count',
'count' => 1,
'path' => __DIR__ . '/../../src/wp-includes/cache-compat.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 \\$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]];
9 changes: 9 additions & 0 deletions tests/phpstan/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@
define( 'FS_TIMEOUT', 1 );
define( 'FS_CHMOD_DIR', 1 );
define( 'FS_CHMOD_FILE', 1 );

// Theme constants referenced in add_theme_support().
define( 'NO_HEADER_TEXT', false );
define( 'HEADER_IMAGE_WIDTH', 0 );
define( 'HEADER_IMAGE_HEIGHT', 0 );
define( 'HEADER_TEXTCOLOR', '' );
define( 'HEADER_IMAGE', '' );
define( 'BACKGROUND_COLOR', '' );
define( 'BACKGROUND_IMAGE', '' );
Loading