diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 20af3959e8ea22..d4d675953268f8 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -683,7 +683,7 @@ class WP_Theme_JSON_Gutenberg { * @return array Responsive media queries. */ public static function get_viewport_media_queries( $viewport_settings = null, $options = array() ) { - $breakpoints = static::sanitize_viewport_settings( $viewport_settings ); + $breakpoints = self::sanitize_viewport_settings( $viewport_settings ); $responsive_media_queries = array(); @@ -753,7 +753,7 @@ private static function is_valid_viewport_breakpoint_size( $value ) { * @return float|null Viewport breakpoint size in pixels, or null when invalid. */ private static function get_viewport_breakpoint_value_in_pixels( $value ) { - if ( ! static::is_valid_viewport_breakpoint_size( $value ) ) { + if ( ! self::is_valid_viewport_breakpoint_size( $value ) ) { return null; } @@ -796,7 +796,7 @@ private static function sanitize_viewport_settings( $viewport_settings ) { $breakpoints = array(); foreach ( array_keys( static::DEFAULT_VIEWPORT_BREAKPOINTS ) as $breakpoint ) { $value = $viewport_settings[ $breakpoint ] ?? null; - $px = static::get_viewport_breakpoint_value_in_pixels( $value ); + $px = self::get_viewport_breakpoint_value_in_pixels( $value ); if ( null !== $px ) { $breakpoints[ $breakpoint ] = array( 'value' => trim( $value ), @@ -986,8 +986,8 @@ private function process_pseudo_selectors( $node, $base_selector, $settings, $bl if ( is_array( $block_metadata ) ) { $feature_declarations = $this->get_feature_declarations_for_node( $block_metadata, $pseudo_node ); - $feature_declarations = static::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ); - $feature_declarations = static::update_button_width_declarations( $feature_declarations, $settings ); + $feature_declarations = self::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ); + $feature_declarations = self::update_button_width_declarations( $feature_declarations, $settings ); foreach ( $feature_declarations as $feature_selector => $declarations ) { $target_selector = is_array( $style_variation ) @@ -1098,7 +1098,7 @@ public function __construct( $theme_json = array( 'version' => WP_Theme_JSON_Gut $valid_block_names = array_keys( $blocks_metadata ); $valid_element_names = array_keys( static::ELEMENTS ); $valid_variations = static::get_valid_block_style_variations( $blocks_metadata ); - $this->theme_json = static::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations ); + $this->theme_json = self::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations ); $this->theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations ); $this->theme_json = static::maybe_opt_in_into_settings( $this->theme_json ); @@ -1136,8 +1136,8 @@ public function __construct( $theme_json = array( 'version' => WP_Theme_JSON_Gut if ( isset( $spacing_scale ) ) { $sizes_path = array( 'settings', 'spacing', 'spacingSizes', $origin ); $spacing_sizes = _wp_array_get( $this->theme_json, $sizes_path, array() ); - $spacing_scale_sizes = static::compute_spacing_sizes( $spacing_scale ); - $merged_spacing_sizes = static::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes ); + $spacing_scale_sizes = self::compute_spacing_sizes( $spacing_scale ); + $merged_spacing_sizes = self::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes ); _wp_array_set( $this->theme_json, $sizes_path, $merged_spacing_sizes ); } } @@ -1513,7 +1513,7 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n $result = static::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] ); if ( 'settings' === $subtree && array_key_exists( 'viewport', $input[ $subtree ] ) ) { - $result['viewport'] = static::sanitize_viewport_settings( $input[ $subtree ]['viewport'] ); + $result['viewport'] = self::sanitize_viewport_settings( $input[ $subtree ]['viewport'] ); } if ( 'settings' === $subtree ) { @@ -1545,7 +1545,7 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n if ( empty( $result ) ) { unset( $output[ $subtree ] ); } else { - $output[ $subtree ] = static::resolve_custom_css_format( $result ); + $output[ $subtree ] = self::resolve_custom_css_format( $result ); } } @@ -2678,7 +2678,7 @@ protected function get_css_variables( $nodes, $origins ) { continue; } - $target = static::get_feature_selector( $feature_selectors, $preset_metadata['path'][0], $selector ); + $target = self::get_feature_selector( $feature_selectors, $preset_metadata['path'][0], $selector ); if ( ! isset( $vars_by_selector[ $target ] ) ) { $vars_by_selector[ $target ] = array(); @@ -3503,7 +3503,7 @@ protected static function get_style_nodes( $theme_json, $selectors = array(), $o if ( ! isset( $block_options['include_block_style_variations'] ) ) { $block_options['include_block_style_variations'] = true; } - $block_nodes = static::get_block_nodes( $theme_json, $selectors, $block_options ); + $block_nodes = self::get_block_nodes( $theme_json, $selectors, $block_options ); foreach ( $block_nodes as $block_node ) { $nodes[] = $block_node; } @@ -3528,7 +3528,7 @@ protected static function get_style_nodes( $theme_json, $selectors = array(), $o * @return array The block nodes in theme.json. */ public function get_styles_block_nodes() { - return static::get_block_nodes( $this->theme_json ); + return self::get_block_nodes( $this->theme_json ); } /** @@ -4124,11 +4124,11 @@ public function get_styles_for_block( $block_metadata ) { // Update text indent selector for paragraph blocks based on the textIndent setting. $block_name = $block_metadata['name'] ?? null; - $feature_declarations = static::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ); + $feature_declarations = self::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ); $block_elements = $block_metadata['elements'] ?? array(); // Update button width declarations for percentage values to use calc() with block gap. - $feature_declarations = static::update_button_width_declarations( $feature_declarations, $settings ); + $feature_declarations = self::update_button_width_declarations( $feature_declarations, $settings ); // If there are style variations, generate the declarations for them, including any feature selectors the block may have. // Responsive nodes (those with a media_query) do not process variations — variation responsive @@ -4146,10 +4146,10 @@ public function get_styles_for_block( $block_metadata ) { $variation_declarations = static::get_feature_declarations_for_node( $block_metadata, $style_variation_node ); // Update text indent selector for paragraph blocks based on the textIndent setting. - $variation_declarations = static::update_paragraph_text_indent_selector( $variation_declarations, $settings, $block_name ); + $variation_declarations = self::update_paragraph_text_indent_selector( $variation_declarations, $settings, $block_name ); // Update button width declarations for percentage values to use calc() with block gap. - $variation_declarations = static::update_button_width_declarations( $variation_declarations, $settings ); + $variation_declarations = self::update_button_width_declarations( $variation_declarations, $settings ); // Combine selectors with style variation's selector and add to overall style variation declarations. foreach ( $variation_declarations as $current_selector => $new_declarations ) { @@ -4162,7 +4162,7 @@ public function get_styles_for_block( $block_metadata ) { $style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json ); // Process pseudo-selectors for this variation (e.g., :hover, :focus). - $block_name = $block_metadata['name'] ?? ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ? static::get_block_name_from_metadata_path( $block_metadata ) : null ); + $block_name = $block_metadata['name'] ?? ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ? self::get_block_name_from_metadata_path( $block_metadata ) : null ); $variation_pseudo_declarations = $this->process_pseudo_selectors( $style_variation_node, $style_variation['selector'], $settings, $block_name, $block_metadata, $style_variation ); $style_variation_declarations = array_merge( $style_variation_declarations, $variation_pseudo_declarations ); @@ -4212,8 +4212,8 @@ public function get_styles_for_block( $block_metadata ) { $breakpoint_media = $responsive_media_queries[ $breakpoint ]; // Process feature-level declarations for this breakpoint. $breakpoint_feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $breakpoint_node ); - $breakpoint_feature_declarations = static::update_paragraph_text_indent_selector( $breakpoint_feature_declarations, $settings, $block_name ); - $breakpoint_feature_declarations = static::update_button_width_declarations( $breakpoint_feature_declarations, $settings ); + $breakpoint_feature_declarations = self::update_paragraph_text_indent_selector( $breakpoint_feature_declarations, $settings, $block_name ); + $breakpoint_feature_declarations = self::update_button_width_declarations( $breakpoint_feature_declarations, $settings ); foreach ( $breakpoint_feature_declarations as $feature_selector => $feature_decl ) { $combined_selectors = static::get_block_style_variation_feature_selector( $style_variation, $feature_selector ); @@ -4429,7 +4429,7 @@ static function ( $pseudo_selector ) use ( $selector ) { // Update declarations if there are separators with only background color defined. if ( '.wp-block-separator' === $selector ) { - $declarations = static::update_separator_declarations( $declarations ); + $declarations = self::update_separator_declarations( $declarations ); } /* @@ -4679,8 +4679,8 @@ public function merge( $incoming ) { // Generate and merge the scales for this layer. $sizes_path = array( 'settings', 'spacing', 'spacingSizes', $origin ); $spacing_sizes = _wp_array_get( $incoming_data, $sizes_path, array() ); - $spacing_scale_sizes = static::compute_spacing_sizes( $flattened_spacing_scale ); - $merged_spacing_sizes = static::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes ); + $spacing_scale_sizes = self::compute_spacing_sizes( $flattened_spacing_scale ); + $merged_spacing_sizes = self::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes ); _wp_array_set( $incoming_data, $sizes_path, $merged_spacing_sizes ); } @@ -4777,7 +4777,7 @@ public function merge( $incoming ) { * some values provide exceptions, namely style values that are * objects and represent unique definitions for the style. */ - $style_nodes = static::get_block_nodes( + $style_nodes = self::get_block_nodes( $this->theme_json, array(), array( 'include_node_paths_only' => true ) @@ -5016,7 +5016,7 @@ public static function remove_insecure_properties( $theme_json, $origin = 'theme } $block_name = in_array( 'blocks', $metadata['path'], true ) - ? static::get_block_name_from_metadata_path( $metadata ) + ? self::get_block_name_from_metadata_path( $metadata ) : null; // The global styles custom CSS is not sanitized, but can only be edited by users with 'edit_css' capability. @@ -5341,13 +5341,13 @@ protected static function remove_insecure_settings( $input, $allow_viewport = tr } // Ensure indirect properties not included in any `PRESETS_METADATA` value are allowed. - static::remove_indirect_properties( $input, $output ); + self::remove_indirect_properties( $input, $output ); // Preserve all valid settings that have type markers in VALID_SETTINGS. self::preserve_valid_typed_settings( $input, $output, static::VALID_SETTINGS ); if ( $allow_viewport && array_key_exists( 'viewport', $input ) ) { - $output['viewport'] = static::sanitize_viewport_settings( $input['viewport'] ); + $output['viewport'] = self::sanitize_viewport_settings( $input['viewport'] ); } return $output; @@ -5381,7 +5381,7 @@ protected static function remove_insecure_styles( $input ) { } // Ensure indirect properties not handled by `compute_style_properties` are allowed. - static::remove_indirect_properties( $input, $output ); + self::remove_indirect_properties( $input, $output ); return $output; } @@ -5698,7 +5698,7 @@ public function set_spacing_sizes() { return null; } - $spacing_sizes = static::compute_spacing_sizes( $spacing_scale ); + $spacing_sizes = self::compute_spacing_sizes( $spacing_scale ); // If there are 7 or less steps in the scale revert to numbers for labels instead of t-shirt sizes. if ( $spacing_scale['steps'] <= 7 ) { @@ -5750,7 +5750,7 @@ private static function merge_spacing_sizes( $base, $incoming ) { * 'operator' => '+', * 'increment' => 2, * ); - * $spacing_sizes = static::compute_spacing_sizes( $spacing_scale ); + * $spacing_sizes = self::compute_spacing_sizes( $spacing_scale ); * // -> array( * // array( 'name' => 'Small', 'slug' => '40', 'size' => '14px' ), * // array( 'name' => 'Medium', 'slug' => '50', 'size' => '16px' ), diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 660f7872a98a98..c654dc24b70b64 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -280,8 +280,8 @@ public static function get_theme_data( $deprecated = array(), $options = array() * * See test_add_registered_block_styles_to_theme_data and test_unwraps_block_style_variations. */ - $theme_json_data = static::inject_variations_from_block_style_variation_files( $theme_json_data, $variations ); - $theme_json_data = static::inject_variations_from_block_styles_registry( $theme_json_data ); + $theme_json_data = self::inject_variations_from_block_style_variation_files( $theme_json_data, $variations ); + $theme_json_data = self::inject_variations_from_block_styles_registry( $theme_json_data ); /** * Filters the data provided by the theme for global styles and settings. @@ -398,7 +398,7 @@ public static function get_block_data() { $config = array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA ); foreach ( $blocks as $block_name => $block_type ) { if ( isset( $block_type->supports['__experimentalStyle'] ) ) { - $config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] ); + $config['styles']['blocks'][ $block_name ] = self::remove_json_comments( $block_type->supports['__experimentalStyle'] ); } if ( @@ -434,7 +434,7 @@ private static function remove_json_comments( $json_array ) { unset( $json_array['//'] ); foreach ( $json_array as $k => $v ) { if ( is_array( $v ) ) { - $json_array[ $k ] = static::remove_json_comments( $v ); + $json_array[ $k ] = self::remove_json_comments( $v ); } } @@ -789,10 +789,10 @@ protected static function get_style_variation_files_from_current_theme() { $base_directory = get_stylesheet_directory() . '/styles'; $template_directory = get_template_directory() . '/styles'; if ( is_dir( $base_directory ) ) { - $variation_files = static::recursively_iterate_json( $base_directory ); + $variation_files = self::recursively_iterate_json( $base_directory ); } if ( is_dir( $template_directory ) && $template_directory !== $base_directory ) { - $variation_files_parent = static::recursively_iterate_json( $template_directory ); + $variation_files_parent = self::recursively_iterate_json( $template_directory ); // If the child and parent variation file basename are the same, only include the child theme's. foreach ( $variation_files_parent as $parent_path => $parent ) { foreach ( $variation_files as $child_path => $child ) { @@ -823,13 +823,13 @@ public static function get_style_variations_from_directory( $directory, $scope = if ( get_stylesheet_directory() === $directory ) { $variation_files = static::get_style_variation_files_from_current_theme(); } else { - $variation_files = static::recursively_iterate_json( $directory ); + $variation_files = self::recursively_iterate_json( $directory ); } } ksort( $variation_files ); foreach ( $variation_files as $path => $file ) { $decoded_file = self::read_json_file( $path ); - if ( is_array( $decoded_file ) && static::style_variation_has_scope( $decoded_file, $scope ) ) { + if ( is_array( $decoded_file ) && self::style_variation_has_scope( $decoded_file, $scope ) ) { $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); $variation = ( new WP_Theme_JSON_Gutenberg( $translated ) )->get_raw_data(); if ( empty( $variation['title'] ) ) { diff --git a/tools/phpstan/baseline.neon b/tools/phpstan/baseline.neon index a0f5b12b4d3ee7..d8aecb817f0874 100644 --- a/tools/phpstan/baseline.neon +++ b/tools/phpstan/baseline.neon @@ -48,90 +48,6 @@ parameters: count: 1 path: ../../lib/class-wp-theme-json-gutenberg.php - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:compute_spacing_sizes\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 3 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:get_block_name_from_metadata_path\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 2 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:get_block_nodes\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 3 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:get_feature_selector\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:get_viewport_breakpoint_value_in_pixels\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:is_valid_viewport_breakpoint_size\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:merge_spacing_sizes\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 2 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:remove_indirect_properties\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 2 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:resolve_custom_css_format\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:sanitize_viewport_settings\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 3 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:unwrap_shared_block_style_variations\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:update_button_width_declarations\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 4 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:update_paragraph_text_indent_selector\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 4 - path: ../../lib/class-wp-theme-json-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Gutenberg\:\:update_separator_declarations\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-gutenberg.php - - message: '#^Static property WP_Theme_JSON_Resolver_Gutenberg\:\:\$blocks \(WP_Theme_JSON_Gutenberg\) does not accept null\.$#' identifier: assign.propertyType @@ -168,36 +84,6 @@ parameters: count: 1 path: ../../lib/class-wp-theme-json-resolver-gutenberg.php - - - message: '#^Unsafe call to private method WP_Theme_JSON_Resolver_Gutenberg\:\:inject_variations_from_block_style_variation_files\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-resolver-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Resolver_Gutenberg\:\:inject_variations_from_block_styles_registry\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-resolver-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Resolver_Gutenberg\:\:recursively_iterate_json\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 3 - path: ../../lib/class-wp-theme-json-resolver-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Resolver_Gutenberg\:\:remove_json_comments\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 2 - path: ../../lib/class-wp-theme-json-resolver-gutenberg.php - - - - message: '#^Unsafe call to private method WP_Theme_JSON_Resolver_Gutenberg\:\:style_variation_has_scope\(\) through static\:\:\.$#' - identifier: staticClassAccess.privateMethod - count: 1 - path: ../../lib/class-wp-theme-json-resolver-gutenberg.php - - message: '#^Call to function method_exists\(\) with ''WP_Interactivity_API'' and ''add_client…'' will always evaluate to true\.$#' identifier: function.alreadyNarrowedType