Skip to content

Commit

Permalink
Update WPCS to v3.0, and fix all reported Coding Standards issues (Wo…
Browse files Browse the repository at this point in the history
…rdPress#53866)

* update composer.json

* Remove invalid rule

* exclude the build folder

* ran phpcbf in the lib folder

* more fixes

* fix assignments in condition

* cleanup composer.json file

* use do-while instead of while(true)

* Update phpunit/experimental/interactivity-api/directive-processing-test.php

Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>

* add a rule in the config file instead of ignoring inside the files

* update ruleset for textdomain

* revert opening php tags

* Ignore empty files in tests/gutenberg-test-themes

* ruleset cleanup for parser.php

* More fixes after rebasing the PR

* fix alignment of param docs

---------

Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
  • Loading branch information
aristath and jrfnl authored Sep 13, 2023
1 parent 0ffb596 commit b05bee7
Show file tree
Hide file tree
Showing 83 changed files with 204 additions and 232 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
}
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
"wp-coding-standards/wpcs": "^2.2",
"wp-coding-standards/wpcs": "^3.0",
"sirbrillig/phpcs-variable-analysis": "^2.8",
"spatie/phpunit-watcher": "^1.23",
"yoast/phpunit-polyfills": "^1.0",
Expand Down
12 changes: 6 additions & 6 deletions lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,24 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
* flag nested under `experimentalBorder` must be enabled for the feature
* to be opted into.
*
* @param WP_Block_Type $block_type Block type to check for support.
* @param string $feature Name of the feature to check support for.
* @param mixed $default Fallback value for feature support, defaults to false.
* @param WP_Block_Type $block_type Block type to check for support.
* @param string $feature Name of the feature to check support for.
* @param mixed $default_value Fallback value for feature support, defaults to false.
*
* @return boolean Whether or not the feature is supported.
*/
function gutenberg_has_border_feature_support( $block_type, $feature, $default = false ) {
function gutenberg_has_border_feature_support( $block_type, $feature, $default_value = false ) {
// Check if all border support features have been opted into via `"__experimentalBorder": true`.
if (
property_exists( $block_type, 'supports' ) &&
( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default ) )
( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default_value ) )
) {
return true;
}

// Check if the specific feature has been opted into individually
// via nested flag under `__experimentalBorder`.
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default );
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value );
}

// Register the block support.
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function gutenberg_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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
);
$updated_content = preg_replace_callback(
$replace_regex,
static function( $matches ) {
static function ( $matches ) {
return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3];
},
$block_content
Expand Down
1 change: 0 additions & 1 deletion lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ function gutenberg_render_typography_support( $block_content, $block ) {
}

return $block_content;

}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function gutenberg_register_core_block_assets( $block_name ) {
if ( ! $stylesheet_removed ) {
add_action(
'wp_enqueue_scripts',
static function() {
static function () {
wp_dequeue_style( 'wp-block-library-theme' );
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/class-wp-duotone-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private static function is_preset( $duotone_attr ) {
* @return string The CSS variable name.
*/
private static function get_css_custom_property_name( $slug ) {
return "--wp--preset--duotone--$slug";
return "--wp--preset--duotone--$slug";
}

/**
Expand All @@ -492,7 +492,7 @@ private static function get_css_custom_property_name( $slug ) {
* @return string The ID of the duotone filter.
*/
private static function get_filter_id( $slug ) {
return "wp-duotone-$slug";
return "wp-duotone-$slug";
}

/**
Expand Down
1 change: 0 additions & 1 deletion lib/class-wp-theme-json-data-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ public function update_with( $new_data ) {
public function get_data() {
return $this->theme_json->get_raw_data();
}

}
13 changes: 6 additions & 7 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ public function get_styles_for_block( $block_metadata ) {
// Prepend the variation selector to the current selector.
$split_selectors = explode( ',', $shortened_selector );
$updated_selectors = array_map(
static function( $split_selector ) use ( $clean_style_variation_selector ) {
static function ( $split_selector ) use ( $clean_style_variation_selector ) {
return $clean_style_variation_selector . $split_selector;
},
$split_selectors
Expand Down Expand Up @@ -2384,7 +2384,7 @@ static function( $split_selector ) use ( $clean_style_variation_selector ) {
$pseudo_matches = array_values(
array_filter(
$element_pseudo_allowed,
static function( $pseudo_selector ) use ( $selector ) {
static function ( $pseudo_selector ) use ( $selector ) {
return str_contains( $selector, $pseudo_selector );
}
)
Expand Down Expand Up @@ -3415,7 +3415,7 @@ public function set_spacing_sizes() {
}

if ( $below_midpoint_count < $steps_mid_point - 2 ) {
$x_small_count++;
++$x_small_count;
}

$slug -= 10;
Expand Down Expand Up @@ -3452,7 +3452,7 @@ public function set_spacing_sizes() {
}

if ( $above_midpoint_count > 1 ) {
$x_large_count++;
++$x_large_count;
}

$slug += 10;
Expand Down Expand Up @@ -3728,16 +3728,15 @@ public static function resolve_variables( $theme_json ) {
$theme_vars = static::compute_theme_vars( $settings );
$vars = array_reduce(
array_merge( $preset_vars, $theme_vars ),
function( $carry, $item ) {
function ( $carry, $item ) {
$name = $item['name'];
$carry[ "var({$name})" ] = $item['value'];
return $carry;
return $carry;
},
array()
);

$theme_json->theme_json['styles'] = self::convert_variables_to_value( $styles, $vars );
return $theme_json;
}

}
12 changes: 6 additions & 6 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,18 @@ public static function get_block_data() {
/**
* When given an array, this will remove any keys with the name `//`.
*
* @param array $array The array to filter.
* @param array $json_array The array to filter.
* @return array The filtered array.
*/
private static function remove_json_comments( $array ) {
unset( $array['//'] );
foreach ( $array as $k => $v ) {
private static function remove_json_comments( $json_array ) {
unset( $json_array['//'] );
foreach ( $json_array as $k => $v ) {
if ( is_array( $v ) ) {
$array[ $k ] = static::remove_json_comments( $v );
$json_array[ $k ] = static::remove_json_comments( $v );
}
}

return $array;
return $json_array;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.3/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function gutenberg_wp_block_register_post_meta() {
$post_type,
'wp_pattern_sync_status',
array(
'auth_callback' => function() {
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
},
'sanitize_callback' => 'sanitize_text_field',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static function get_fallback_classic_menu() {
private static function get_most_recently_created_nav_menu( $classic_nav_menus ) {
usort(
$classic_nav_menus,
static function( $a, $b ) {
static function ( $a, $b ) {
return $b->term_id - $a->term_id;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ private function parse_next_tag() {

if ( '/' === $this->html[ $at + 1 ] ) {
$this->is_closing_tag = true;
$at++;
++$at;
} else {
$this->is_closing_tag = false;
}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ private function parse_next_tag() {
*
* See https://html.spec.whatwg.org/#parse-error-incorrectly-closed-comment
*/
$closer_at--; // Pre-increment inside condition below reduces risk of accidental infinite looping.
--$closer_at; // Pre-increment inside condition below reduces risk of accidental infinite looping.
while ( ++$closer_at < strlen( $html ) ) {
$closer_at = strpos( $html, '--', $closer_at );
if ( false === $closer_at ) {
Expand Down Expand Up @@ -1097,7 +1097,7 @@ private function parse_next_tag() {
* See https://html.spec.whatwg.org/#parse-error-missing-end-tag-name
*/
if ( '>' === $html[ $at + 1 ] ) {
$at++;
++$at;
continue;
}

Expand Down Expand Up @@ -1739,7 +1739,7 @@ public function get_attribute( $name ) {
* @param string $prefix Prefix of requested attribute names.
* @return array|null List of attribute names, or `null` when no tag opener is matched.
*/
function get_attribute_names_with_prefix( $prefix ) {
public function get_attribute_names_with_prefix( $prefix ) {
if ( $this->is_closing_tag || null === $this->tag_name_starts_at ) {
return null;
}
Expand Down Expand Up @@ -2282,11 +2282,9 @@ private function matches() {
* See https://html.spec.whatwg.org/#attributes-3
* See https://html.spec.whatwg.org/#space-separated-tokens
*/
while (
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
false !== ( $class_at = strpos( $this->html, $this->sought_class_name, $class_at ) ) &&
$class_at < $class_end
) {
do {
$class_at = strpos( $this->html, $this->sought_class_name, $class_at );

/*
* Verify this class starts at a boundary.
*/
Expand All @@ -2312,7 +2310,7 @@ private function matches() {
}

return true;
}
} while ( false !== $class_at && $class_at < $class_end );

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/compat/wordpress-6.3/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function add_modified_wp_template_schema() {
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'get_callback' => function( $object ) {
if ( ! empty( $object['wp_id'] ) ) {
$post = get_post( $object['wp_id'] );
'get_callback' => function ( $template_object ) {
if ( ! empty( $template_object['wp_id'] ) ) {
$post = get_post( $template_object['wp_id'] );
if ( $post && isset( $post->post_modified ) ) {
return mysql_to_rfc3339( $post->post_modified );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.3/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function _gutenberg_get_iframed_editor_assets() {

add_filter(
'block_editor_settings_all',
static function( $settings ) {
static function ( $settings ) {
// We must override what core is passing now.
$settings['__unstableResolvedAssets'] = _gutenberg_get_iframed_editor_assets();
return $settings;
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.4/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function wp_print_font_faces( $fonts = array() ) {
// @core-merge: do not merge this code into Core.
add_filter(
'block_editor_settings_all',
static function( $settings ) {
static function ( $settings ) {
ob_start();
// @core-merge: add only this line into Core's `_wp_get_iframed_editor_assets()` function after `wp_print_styles()`.
wp_print_font_faces();
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.4/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function _gutenberg_get_iframed_editor_assets_6_4() {

add_filter(
'block_editor_settings_all',
static function( $settings ) {
static function ( $settings ) {
// We must override what core is passing now.
$settings['__unstableResolvedAssets'] = _gutenberg_get_iframed_editor_assets_6_4();
return $settings;
Expand Down
10 changes: 5 additions & 5 deletions lib/experimental/block-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function gutenberg_add_hooked_block( $hooked_block, $position, $anchor_block ) {
* @return callable A function that accepts a block's content and returns the content with the inserted block.
*/
function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $anchor_block_type ) {
return function( $block ) use ( $inserted_block, $relative_position, $anchor_block_type ) {
return function ( $block ) use ( $inserted_block, $relative_position, $anchor_block_type ) {
if ( $anchor_block_type === $block['blockName'] ) {
if ( 'first_child' === $relative_position ) {
array_unshift( $block['innerBlocks'], $inserted_block );
Expand All @@ -173,17 +173,17 @@ function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $an
$anchor_block_index = array_search( $anchor_block_type, array_column( $block['innerBlocks'], 'blockName' ), true );
if ( false !== $anchor_block_index && ( 'after' === $relative_position || 'before' === $relative_position ) ) {
if ( 'after' === $relative_position ) {
$anchor_block_index++;
++$anchor_block_index;
}
array_splice( $block['innerBlocks'], $anchor_block_index, 0, array( $inserted_block ) );

// Find matching `innerContent` chunk index.
$chunk_index = 0;
while ( $anchor_block_index > 0 ) {
if ( ! is_string( $block['innerContent'][ $chunk_index ] ) ) {
$anchor_block_index--;
--$anchor_block_index;
}
$chunk_index++;
++$chunk_index;
}
// Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`)
// when rendering blocks, we also need to insert a value (`null`, to mark a block
Expand All @@ -204,7 +204,7 @@ function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $an
* @return callable A filter for the `rest_prepare_block_type` hook that adds a `block_hooks` field to the network response.
*/
function gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_block_type, $position, $anchor_block_type ) {
return function( $response, $block_type ) use ( $inserted_block_type, $position, $anchor_block_type ) {
return function ( $response, $block_type ) use ( $inserted_block_type, $position, $anchor_block_type ) {
if ( $block_type->name !== $inserted_block_type ) {
return $response;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/experimental/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function wp_enqueue_block_view_script( $block_name, $args ) {
* is to ensure the content exists.
* @return string Block content.
*/
$callback = static function( $content, $block ) use ( $args, $block_name ) {
$callback = static function ( $content, $block ) use ( $args, $block_name ) {

// Sanity check.
if ( empty( $block['blockName'] ) || $block_name !== $block['blockName'] ) {
Expand Down Expand Up @@ -185,7 +185,7 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst
);
if ( ! $found ) {
return $block_content;
};
}
$tag_name = $tags->get_tag();
$markup = "<$tag_name>$custom_value</$tag_name>";
$updated_tags = new WP_HTML_Tag_Processor( $markup );
Expand Down
1 change: 0 additions & 1 deletion lib/experimental/class-wp-rest-customizer-nonces.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ public function get_save_nonce() {
'stylesheet' => $wp_customize->get_stylesheet(),
);
}

}
12 changes: 6 additions & 6 deletions lib/experimental/fonts-api/bc-layer/class-wp-web-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function __construct() {
* @type string $provider_id => array {
* An associate array of provider's class name and fonts.
*
* @type string $class Fully qualified name of the provider's class.
* @type string[] $fonts An array of enqueued font handles for this provider.
* @type string $class_name Fully qualified name of the provider's class.
* @type string[] $fonts An array of enqueued font handles for this provider.
* }
* }
*/
Expand All @@ -80,16 +80,16 @@ public function get_providers() {
* @since X.X.X
*
* @param string $provider_id The provider's unique ID.
* @param string $class The provider class name.
* @param string $class_name The provider class name.
* @return bool True if successfully registered, else false.
*/
public function register_provider( $provider_id, $class ) {
if ( empty( $provider_id ) || empty( $class ) || ! class_exists( $class ) ) {
public function register_provider( $provider_id, $class_name ) {
if ( empty( $provider_id ) || empty( $class_name ) || ! class_exists( $class_name ) ) {
return false;
}

$this->providers[ $provider_id ] = array(
'class' => $class,
'class' => $class_name,
'fonts' => array(),
);
return true;
Expand Down
Loading

0 comments on commit b05bee7

Please sign in to comment.