From 219483f0940c36789988f7e900581564ad5da958 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 25 Sep 2023 15:34:34 +0000 Subject: [PATCH] Coding Standards: Fix a few newly introduced WPCS issues. Follow-up to [56570], [56573], [56589], [56604], [56612], [56620], [56629], [56631], [56638], [56642], [56644], [56649]. Props jrf. See #59161, #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56680 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/options-general.php | 2 +- src/wp-admin/plugins.php | 2 +- src/wp-admin/user-edit.php | 2 +- src/wp-includes/block-supports/elements.php | 2 +- src/wp-includes/blocks.php | 33 +++++++++++-------- src/wp-includes/media.php | 2 +- src/wp-includes/taxonomy.php | 4 +-- .../phpunit/tests/admin/wpTermsListTable.php | 8 ++--- tests/phpunit/tests/blocks/editor.php | 1 - tests/phpunit/tests/media.php | 4 +-- tests/phpunit/tests/vars.php | 10 +++--- 11 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/wp-admin/options-general.php b/src/wp-admin/options-general.php index 9d0102f5ad0eb..490a138580c5f 100644 --- a/src/wp-admin/options-general.php +++ b/src/wp-admin/options-general.php @@ -140,7 +140,7 @@ ' . esc_html( $new_admin_email ) . '' diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 7ec59ae40bcc0..13a28e127e6aa 100644 --- a/src/wp-admin/plugins.php +++ b/src/wp-admin/plugins.php @@ -690,7 +690,7 @@ ); } elseif ( isset( $_GET['deleted'] ) ) { - $delete_result = get_transient( 'plugins_delete_result_' . $user_ID ); + $delete_result = get_transient( 'plugins_delete_result_' . $user_ID ); // Delete it once we're done. delete_transient( 'plugins_delete_result_' . $user_ID ); diff --git a/src/wp-admin/user-edit.php b/src/wp-admin/user-edit.php index d9b630e058184..04bf5ac512dac 100644 --- a/src/wp-admin/user-edit.php +++ b/src/wp-admin/user-edit.php @@ -550,7 +550,7 @@ $new_email = get_user_meta( $current_user->ID, '_new_email', true ); if ( $new_email && $new_email['newemail'] !== $current_user->user_email && $profile_user->ID === $current_user->ID ) : - $pending_change_message = sprintf( + $pending_change_message = sprintf( /* translators: %s: New email. */ __( 'There is a pending change of your email to %s.' ), '' . esc_html( $new_email['newemail'] ) . '' diff --git a/src/wp-includes/block-supports/elements.php b/src/wp-includes/block-supports/elements.php index a388ad403fb3a..f5469f00b3fef 100644 --- a/src/wp-includes/block-supports/elements.php +++ b/src/wp-includes/block-supports/elements.php @@ -98,7 +98,7 @@ function wp_render_elements_support( $block_content, $block ) { foreach ( $element_config['paths'] as $path ) { if ( null !== _wp_array_get( $block['attrs'], explode( '.', $path ), null ) ) { - $element_colors_set++; + ++$element_colors_set; } } } diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 323719efc4814..be387b89a983e 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -790,20 +790,20 @@ function make_before_block_visitor( $context ) { * Furthermore, prepend the markup for any blocks hooked `before` the given block and as its parent's * `first_child`, respectively, to the serialized markup for the given block. * - * @param array $block The block to inject the theme attribute into, and hooked blocks before. - * @param array $parent The parent block of the given block. - * @param array $prev The previous sibling block of the given block. + * @param array $block The block to inject the theme attribute into, and hooked blocks before. + * @param array $parent_block The parent block of the given block. + * @param array $prev The previous sibling block of the given block. * @return string The serialized markup for the given block, with the markup for any hooked blocks prepended to it. */ - return function( &$block, $parent = null, $prev = null ) use ( $context ) { + return function ( &$block, $parent_block = null, $prev = null ) use ( $context ) { _inject_theme_attribute_in_template_part_block( $block ); $markup = ''; - if ( $parent && ! $prev ) { + if ( $parent_block && ! $prev ) { // Candidate for first-child insertion. $relative_position = 'first_child'; - $anchor_block_type = $parent['blockName']; + $anchor_block_type = $parent_block['blockName']; $hooked_block_types = array_keys( get_hooked_blocks( $anchor_block_type, $relative_position ) ); /** * Filters the list of hooked block types for a given anchor block type and relative position. @@ -856,12 +856,12 @@ function make_after_block_visitor( $context ) { * Append the markup for any blocks hooked `after` the given block and as its parent's * `last_child`, respectively, to the serialized markup for the given block. * - * @param array $block The block to inject the hooked blocks after. - * @param array $parent The parent block of the given block. - * @param array $next The next sibling block of the given block. + * @param array $block The block to inject the hooked blocks after. + * @param array $parent_block The parent block of the given block. + * @param array $next The next sibling block of the given block. * @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it. */ - return function( &$block, $parent = null, $next = null ) use ( $context ) { + return function ( &$block, $parent_block = null, $next = null ) use ( $context ) { $markup = ''; $relative_position = 'after'; @@ -873,10 +873,10 @@ function make_after_block_visitor( $context ) { $markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' ); } - if ( $parent && ! $next ) { + if ( $parent_block && ! $next ) { // Candidate for last-child insertion. $relative_position = 'last_child'; - $anchor_block_type = $parent['blockName']; + $anchor_block_type = $parent_block['blockName']; $hooked_block_types = array_keys( get_hooked_blocks( $anchor_block_type, $relative_position ) ); /** This filter is documented in wp-includes/blocks.php */ $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); @@ -1059,6 +1059,7 @@ function traverse_and_serialize_block( $block, $pre_callback = null, $post_callb $prev = 0 === $block_index ? null : $block['innerBlocks'][ $block_index - 1 ]; + $block_content .= call_user_func_array( $pre_callback, array( &$inner_block, $block, $prev ) @@ -1071,12 +1072,13 @@ function traverse_and_serialize_block( $block, $pre_callback = null, $post_callb $next = count( $block['innerBlocks'] ) - 1 === $block_index ? null : $block['innerBlocks'][ $block_index + 1 ]; + $block_content .= call_user_func_array( $post_callback, array( &$inner_block, $block, $next ) ); } - $block_index++; + ++$block_index; } } @@ -1130,22 +1132,27 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal $prev = 0 === $index ? null : $blocks[ $index - 1 ]; + $result .= call_user_func_array( $pre_callback, array( &$block, null, $prev ) // At the top level, there is no parent block to pass to the callback. ); } + $result .= traverse_and_serialize_block( $block, $pre_callback, $post_callback ); + if ( is_callable( $post_callback ) ) { $next = count( $blocks ) - 1 === $index ? null : $blocks[ $index + 1 ]; + $result .= call_user_func_array( $post_callback, array( &$block, null, $next ) // At the top level, there is no parent block to pass to the callback. ); } } + return $result; } diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 56624bdc6b7b4..7febe0c063704 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -5730,7 +5730,7 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { if ( null === $maybe_in_viewport ) { $header_enforced_contexts = array( 'template_part_' . WP_TEMPLATE_PART_AREA_HEADER => true, - 'get_header_image_tag' => true, + 'get_header_image_tag' => true, ); /** diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index be1faaeba5e1f..f0e3be17d34c2 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -231,8 +231,8 @@ function create_initial_taxonomies() { 'publicly_queryable' => false, 'hierarchical' => false, 'labels' => array( - 'name' => _x( 'Pattern Categories', 'taxonomy general name' ), - 'singular_name' => _x( 'Pattern Category', 'taxonomy singular name' ), + 'name' => _x( 'Pattern Categories', 'taxonomy general name' ), + 'singular_name' => _x( 'Pattern Category', 'taxonomy singular name' ), ), 'query_var' => false, 'rewrite' => false, diff --git a/tests/phpunit/tests/admin/wpTermsListTable.php b/tests/phpunit/tests/admin/wpTermsListTable.php index 2eb566d970ee0..c16d9188cd64d 100644 --- a/tests/phpunit/tests/admin/wpTermsListTable.php +++ b/tests/phpunit/tests/admin/wpTermsListTable.php @@ -41,16 +41,16 @@ public function set_up() { /** * Call an inaccessible (private or protected) method. * - * @param object|string $object Object instance or class string to call the method of. + * @param object|string $instance Object instance or class string to call the method of. * @param string $method_name Name of the method to call. * @param array $args Optional. Array of arguments to pass to the method. * @return mixed Return value of the method call. * @throws ReflectionException If the object could not be reflected upon. */ - private function call_inaccessible_method( $object, $method_name, $args = array() ) { - $method = ( new ReflectionClass( $object ) )->getMethod( $method_name ); + private function call_inaccessible_method( $instance, $method_name, $args = array() ) { + $method = ( new ReflectionClass( $instance ) )->getMethod( $method_name ); $method->setAccessible( true ); - return $method->invokeArgs( $object, $args ); + return $method->invokeArgs( $instance, $args ); } /** diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index a6f400e1678bf..f319ace413928 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -543,7 +543,6 @@ public function test_get_block_editor_settings_without_post_content_block() { $settings = get_block_editor_settings( array(), $post_editor_context ); $this->assertArrayNotHasKey( 'postContentAttributes', $settings ); - } /** diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 8ee5536b6da14..f1cd87dd717f1 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -4436,7 +4436,7 @@ public function test_wp_get_loading_optimization_attributes_should_return_empty_ $result = null; add_filter( 'the_content', - function( $content ) use ( &$result ) { + function ( $content ) use ( &$result ) { $attr = $this->get_width_height_for_high_priority(); $result = wp_get_loading_optimization_attributes( 'img', $attr, 'something_completely_arbitrary' ); return $content; @@ -4496,7 +4496,7 @@ public function test_wp_loading_optimization_force_header_contexts_filter() { add_filter( 'wp_loading_optimization_force_header_contexts', - function( $context ) { + function ( $context ) { $contexts['something_completely_arbitrary'] = true; return $contexts; } diff --git a/tests/phpunit/tests/vars.php b/tests/phpunit/tests/vars.php index ceb0a69c7ca63..698f61a0e9794 100644 --- a/tests/phpunit/tests/vars.php +++ b/tests/phpunit/tests/vars.php @@ -34,7 +34,7 @@ public function tear_down() { * * @return array */ - function get_data_to_test_wp_is_mobile(): array { + public function get_data_to_test_wp_is_mobile(): array { return array( 'mobile client hint' => array( 'headers' => array( @@ -104,8 +104,6 @@ function get_data_to_test_wp_is_mobile(): array { } /** - * Tests that wp_is_mobile() . - * * @ticket 59370 * * @covers ::wp_is_mobile @@ -115,7 +113,7 @@ function get_data_to_test_wp_is_mobile(): array { * @param array $headers Headers in $_SERVER. * @param bool $expected Whether expected. */ - function test_wp_is_mobile( array $headers, bool $expected ) { + public function test_wp_is_mobile( array $headers, bool $expected ) { foreach ( $headers as $key => $value ) { $_SERVER[ $key ] = $value; } @@ -127,7 +125,7 @@ function test_wp_is_mobile( array $headers, bool $expected ) { * * @covers ::wp_is_mobile */ - function test_wp_is_mobile_is_true_with_filter() { + public function test_wp_is_mobile_is_true_with_filter() { $this->assertFalse( wp_is_mobile() ); add_filter( 'wp_is_mobile', '__return_true' ); $this->assertTrue( wp_is_mobile() ); @@ -138,7 +136,7 @@ function test_wp_is_mobile_is_true_with_filter() { * * @covers ::wp_is_mobile */ - function test_wp_is_mobile_is_false_with_filter() { + public function test_wp_is_mobile_is_false_with_filter() { $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.60 Mobile Safari/537.36'; $this->assertTrue( wp_is_mobile() ); add_filter( 'wp_is_mobile', '__return_false' );