From 5083ab1b4008c2780a4eba0df467c4ba156f74de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Tue, 4 Feb 2020 21:46:37 +0100 Subject: [PATCH 1/2] Return bool as WP_Scripts::do_item does https://developer.wordpress.org/reference/classes/wp_scripts/do_item/ Discovered by @phpstan on Level 4 --- wp-includes/class-wp-service-worker-scripts.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-service-worker-scripts.php b/wp-includes/class-wp-service-worker-scripts.php index abfedc90d..4820fdda1 100644 --- a/wp-includes/class-wp-service-worker-scripts.php +++ b/wp-includes/class-wp-service-worker-scripts.php @@ -148,7 +148,7 @@ public function get_all() { * * @param string $handle Handle. * @param bool $group Group. Unused. - * @return void + * @return bool */ public function do_item( $handle, $group = false ) { $registered = $this->registered[ $handle ]; @@ -176,6 +176,8 @@ public function do_item( $handle, $group = false ) { @_doing_it_wrong( 'WP_Service_Worker_Scripts::register', esc_html( $error ), '0.1' ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.NoSilencedErrors.Discouraged -- We want the error in the PHP log, but not in the JS output. printf( "console.warn( %s );\n", wp_service_worker_json_encode( $error ) ); // phpcs:ignore WordPress.XSS.EscapeOutput, WordPress.Security.EscapeOutput } + + return $invalid; } /** From e79907507fc79918278a78f8377a3c7887d55183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 10 Feb 2020 19:08:01 +0100 Subject: [PATCH 2/2] Add comment, return negated $invalid as per Pascal asked --- wp-includes/class-wp-service-worker-scripts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp-service-worker-scripts.php b/wp-includes/class-wp-service-worker-scripts.php index 4820fdda1..efc5ef510 100644 --- a/wp-includes/class-wp-service-worker-scripts.php +++ b/wp-includes/class-wp-service-worker-scripts.php @@ -148,7 +148,7 @@ public function get_all() { * * @param string $handle Handle. * @param bool $group Group. Unused. - * @return bool + * @return bool True on success, false on failure. */ public function do_item( $handle, $group = false ) { $registered = $this->registered[ $handle ]; @@ -177,7 +177,7 @@ public function do_item( $handle, $group = false ) { printf( "console.warn( %s );\n", wp_service_worker_json_encode( $error ) ); // phpcs:ignore WordPress.XSS.EscapeOutput, WordPress.Security.EscapeOutput } - return $invalid; + return ! $invalid; } /**