From 7b8bc7d3c1b7fa8ff4d0229fe5654ae38e22db5c Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Sun, 16 Aug 2026 11:25:04 -0700 Subject: [PATCH 1/6] fix: removes baseline for catch.neverThrown --- phpstan.neon.dist | 1 - .../html-api/class-wp-html-processor.php | 5 ++++ .../phpstan/baselines/catch.neverThrown.neon | 25 ------------------- 3 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 tests/phpstan/baselines/catch.neverThrown.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e2e72fb367482..ceaa13887a162 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -36,7 +36,6 @@ includes: - tests/phpstan/baselines/booleanOr.alwaysFalse.neon - tests/phpstan/baselines/booleanOr.alwaysTrue.neon - tests/phpstan/baselines/booleanOr.rightAlwaysTrue.neon - - tests/phpstan/baselines/catch.neverThrown.neon - tests/phpstan/baselines/class.notFound.neon - tests/phpstan/baselines/deadCode.unreachable.neon - tests/phpstan/baselines/empty.offset.neon diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index b4c590ef5141a..813ad1e6d31f6 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -1633,6 +1633,7 @@ private function step_initial(): bool { * @since 6.7.0 * @ignore * + * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document. * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input. * * @see https://html.spec.whatwg.org/#the-before-html-insertion-mode @@ -1733,6 +1734,7 @@ private function step_before_html(): bool { * @since 6.7.0 * @ignore * + * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document. * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input. * * @see https://html.spec.whatwg.org/#the-before-head-insertion-mode @@ -2163,6 +2165,7 @@ private function step_in_head_noscript(): bool { * @since 6.7.0 * @ignore * + * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document. * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input. * * @see https://html.spec.whatwg.org/#the-after-head-insertion-mode @@ -3431,6 +3434,7 @@ private function in_body_any_other_end_tag(): bool { * @since 6.7.0 * @ignore * + * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document. * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input. * * @see https://html.spec.whatwg.org/#parsing-main-intable @@ -3905,6 +3909,7 @@ private function step_in_column_group(): bool { * @since 6.7.0 * @ignore * + * @throws Exception When unable to allocate a bookmark for the next token in the input HTML document. * @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input. * * @see https://html.spec.whatwg.org/#parsing-main-intbody diff --git a/tests/phpstan/baselines/catch.neverThrown.neon b/tests/phpstan/baselines/catch.neverThrown.neon deleted file mode 100644 index 30c8a4a7cfe4b..0000000000000 --- a/tests/phpstan/baselines/catch.neverThrown.neon +++ /dev/null @@ -1,25 +0,0 @@ -# PHPStan baseline for the `catch.neverThrown` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/catch.neverThrown -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=catch.neverThrown -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Dead catch \- Exception is never thrown in the try block\.$#' - identifier: catch.neverThrown - count: 1 - path: ../../../src/wp-includes/html-api/class-wp-html-processor.php From 0d85cb40a8141a898665568d634b58a3ac3097fb Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Sun, 16 Aug 2026 12:59:40 -0700 Subject: [PATCH 2/6] refactor: don't read the property, but use the method --- src/wp-includes/html-api/class-wp-html-processor.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 813ad1e6d31f6..1d3977182c36b 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -804,7 +804,7 @@ public function next_token(): bool { private function next_visitable_token(): bool { $this->current_element = null; - if ( isset( $this->last_error ) ) { + if ( null !== $this->get_last_error() ) { return false; } @@ -823,7 +823,7 @@ private function next_visitable_token(): bool { return $this->next_visitable_token(); } - if ( isset( $this->last_error ) ) { + if ( null !== $this->get_last_error() ) { return false; } } @@ -1019,7 +1019,7 @@ public function expects_closer( ?WP_HTML_Token $node = null ): ?bool { */ public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool { // Refuse to proceed if there was a previous error. - if ( null !== $this->last_error ) { + if ( null !== $this->get_last_error() ) { return false; } @@ -1063,7 +1063,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool { try { $bookmark_name = $this->bookmark_token(); } catch ( Exception $e ) { - if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) { + if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->get_last_error() ) { return false; } throw $e; @@ -1175,7 +1175,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool { */ return false; } catch ( Exception $e ) { - if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) { + if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->get_last_error() ) { return false; } // Rethrow any other exceptions for higher-level handling. @@ -5171,7 +5171,7 @@ public function get_namespace(): string { * @return string|null Name of currently matched tag in input HTML, or `null` if none found. */ public function get_tag(): ?string { - if ( null !== $this->last_error ) { + if ( null !== $this->get_last_error() ) { return null; } From 01b44a4fe0220b5312e68419524fb34864bca4bb Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Sun, 16 Aug 2026 13:00:13 -0700 Subject: [PATCH 3/6] fix: empty check already covers the boolean false case --- .../rest-api/endpoints/class-wp-rest-users-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 9b25cf7974cbc..9c5ec95849178 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -179,7 +179,7 @@ public function check_reassign( $value, $request, $param ) { return $value; } - if ( empty( $value ) || false === $value || 'false' === $value ) { + if ( empty( $value ) || 'false' === $value ) { return false; } From 647751544cf25f142367d84b3af31a0cc76df30b Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Sun, 16 Aug 2026 13:02:44 -0700 Subject: [PATCH 4/6] fix: removes dead code. See line #174 of the same file --- src/wp-admin/plugins.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 5c65801631869..520bd03dee20a 100644 --- a/src/wp-admin/plugins.php +++ b/src/wp-admin/plugins.php @@ -740,8 +740,6 @@ wp_admin_notice( __( 'Plugin deactivated.' ), $updated_notice_args ); } elseif ( isset( $_GET['deactivate-multi'] ) ) { wp_admin_notice( __( 'Selected plugins deactivated.' ), $updated_notice_args ); -} elseif ( 'update-selected' === $action ) { - wp_admin_notice( __( 'All selected plugins are up to date.' ), $updated_notice_args ); } elseif ( isset( $_GET['resume'] ) ) { wp_admin_notice( __( 'Plugin resumed.' ), $updated_notice_args ); } elseif ( isset( $_GET['enabled-auto-update'] ) ) { From 0eac57fbd278f95440f67b584a411eeb8b36923d Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Sun, 16 Aug 2026 13:03:26 -0700 Subject: [PATCH 5/6] fix: marks get_last_error method as impure - state can change its result --- src/wp-includes/html-api/class-wp-html-processor.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 1d3977182c36b..dabdd7c5dc72d 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -642,6 +642,8 @@ private function bail( string $message ) { * @see self::ERROR_UNSUPPORTED * @see self::ERROR_EXCEEDED_MAX_BOOKMARKS * + * @phpstan-impure + * * @return string|null The last error, if one exists, otherwise null. */ public function get_last_error(): ?string { From ef0d247967d86d0734d91838c51f81594b5d43df Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Sun, 16 Aug 2026 13:04:07 -0700 Subject: [PATCH 6/6] feat: removes covered cases of identical.alwaysFalse baseline --- .../phpstan/baselines/identical.alwaysFalse.neon | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/phpstan/baselines/identical.alwaysFalse.neon b/tests/phpstan/baselines/identical.alwaysFalse.neon index 53a42542a0410..d8d766d45827f 100644 --- a/tests/phpstan/baselines/identical.alwaysFalse.neon +++ b/tests/phpstan/baselines/identical.alwaysFalse.neon @@ -18,23 +18,8 @@ parameters: ignoreErrors: - - - message: '#^Strict comparison using \=\=\= between ''update\-selected'' and mixed~\(''activate''\|''activate\-selected''\|''deactivate''\|''deactivate\-selected''\|''delete\-selected''\|''disable\-auto\-update''\|''disable\-auto\-update\-selected''\|''enable\-auto\-update''\|''enable\-auto\-update\-selected''\|''error_scrape''\|''resume''\|''update\-selected''\) will always evaluate to false\.$#' - identifier: identical.alwaysFalse - count: 1 - path: ../../../src/wp-admin/plugins.php - - - message: '#^Strict comparison using \=\=\= between ''exceeded\-max…'' and null will always evaluate to false\.$#' - identifier: identical.alwaysFalse - count: 1 - path: ../../../src/wp-includes/html-api/class-wp-html-processor.php - message: '#^Strict comparison using \=\=\= between 3000000000 and 2147483647 will always evaluate to false\.$#' identifier: identical.alwaysFalse count: 1 path: ../../../src/wp-includes/pluggable.php - - - message: '#^Strict comparison using \=\=\= between false and mixed will always evaluate to false\.$#' - identifier: identical.alwaysFalse - count: 1 - path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php