From f83a37fc27ef59ff68e144b366bfeb61fc7e23c4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 26 Aug 2026 07:32:29 +0000 Subject: [PATCH] Exclude the wp-compat false positives from the PHPStan config The johnbillion/wp-compat extension that comes with wp-cli-tests checks every WordPress symbol against the WordPress 4.9 baseline that wp-cli-tests configures, and only recognizes function_exists() and method_exists() guards. It cannot see the per-command `before_invoke` checks in block-command.php, so all 28 errors it reports are false positives. Every flagged symbol turns out to sit at or below the gate of the command that uses it: WordPress 5.0 for `wp block type` and `wp block synced-pattern`, 5.3 for `wp block style`, 5.5 for `wp block pattern` and `wp block pattern-category`, 5.8 against a 5.9 gate for `wp block template`, and 6.5 for `wp block binding`. Ignore them per file, matching on the message as well as the identifier so that each entry pins the version its command is gated on. A call to anything newer than that gate keeps being reported rather than swallowed by a file-wide ignore. Co-authored-by: Pascal Birchler --- phpstan.neon.dist | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0917bc3..8ffb46d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -64,3 +64,52 @@ parameters: - message: '#Access to an undefined property WP_Block_Type::#' reportUnmatched: false + # johnbillion/wp-compat checks every WordPress symbol against the WordPress 4.9 + # baseline that wp-cli-tests configures. It only recognizes function_exists() and + # method_exists() guards, so it cannot see the per-command `before_invoke` checks in + # block-command.php, and reports every block API symbol as an error. + # + # Each entry below matches on the message as well as the identifier, pinning the + # version that the corresponding command is gated on, so a call to anything newer + # than that gate still gets reported rather than swallowed by a file-wide ignore. + + # `wp block type` is gated on WordPress 5.0. + - + identifier: WPCompat.methodNotAvailable + message: '#^(WP_Block_Type::is_dynamic|WP_Block_Type_Registry::(get_all_registered|get_instance|get_registered|is_registered))\(\) is only available since WordPress version 5\.0\.0\.$#' + path: src/Block_Type_Command.php + + # `wp block synced-pattern` is gated on WordPress 5.0. + - + identifier: WPCompat.functionNotAvailable + message: '#^parse_blocks\(\) is only available since WordPress version 5\.0\.0\.$#' + path: src/Block_Synced_Pattern_Command.php + + # `wp block style` is gated on WordPress 5.3. + - + identifier: WPCompat.methodNotAvailable + message: '#^WP_Block_Styles_Registry::(get_all_registered|get_instance|get_registered_styles_for_block)\(\) is only available since WordPress version 5\.3\.0\.$#' + path: src/Block_Style_Command.php + + # `wp block pattern` and `wp block pattern-category` are gated on WordPress 5.5. + - + identifier: WPCompat.methodNotAvailable + message: '#^WP_Block_Patterns_Registry::(get_all_registered|get_instance|get_registered)\(\) is only available since WordPress version 5\.5\.0\.$#' + path: src/Block_Pattern_Command.php + - + identifier: WPCompat.methodNotAvailable + message: '#^WP_Block_Pattern_Categories_Registry::(get_all_registered|get_instance|get_registered)\(\) is only available since WordPress version 5\.5\.0\.$#' + path: src/Block_Pattern_Category_Command.php + + # `wp block template` is gated on WordPress 5.9, so the WordPress 5.8 template + # functions it calls are comfortably covered. + - + identifier: WPCompat.functionNotAvailable + message: '#^get_block_templates?\(\) is only available since WordPress version 5\.8\.0\.$#' + path: src/Block_Template_Command.php + + # `wp block binding` is gated on WordPress 6.5. + - + identifier: WPCompat.functionNotAvailable + message: '#^(get_all_registered_block_bindings_sources|get_block_bindings_source)\(\) is only available since WordPress version 6\.5\.0\.$#' + path: src/Block_Binding_Command.php