Make WordPress Core

Changeset 63384


Ignore:
Timestamp:
08/28/2026 04:57:25 AM (less than one hour ago)
Author:
westonruter
Message:

Code Quality: Call WP_Theme_JSON's private statics via self::.

In r52744 this class's internal calls were rewritten from self:: to static:: so that the subclasses it was opening the class up to could override them. For a private method that buys nothing, since a subclass cannot supply one, and PHPStan reports it as unsafe: late static binding resolves static:: to the runtime class, where the private method is not visible. Thirty such call sites were left, reaching fourteen private statics. All fourteen are declared private static on WP_Theme_JSON itself, so self:: is behavior-identical. A docblock example on compute_spacing_sizes() showed the same form and is updated along with the code it documents.

This now eliminates the tests/phpstan/baselines/staticClassAccess.privateMethod.neon baseline. In r63368 the identifier was cleared from the four other classes reporting it, and WP_Theme_JSON was the last.

Developed as subset of https://github.com/WordPress/wordpress-develop/pull/13064.
Follow-up to r52744, r63020, r63368.

See #65817.

Location:
trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpstan.neon.dist

    r63381 r63384  
    7979        - tests/phpstan/baselines/return.unusedType.neon
    8080        - tests/phpstan/baselines/smallerOrEqual.alwaysTrue.neon
    81         - tests/phpstan/baselines/staticClassAccess.privateMethod.neon
    8281        - tests/phpstan/baselines/ternary.alwaysTrue.neon
    8382        - tests/phpstan/baselines/varTag.noVariable.neon
  • trunk/src/wp-includes/class-wp-theme-json.php

    r63171 r63384  
    719719         */
    720720        public static function get_viewport_media_queries( $viewport_settings = null, $options = array() ) {
    721                 $breakpoints = static::sanitize_viewport_settings( $viewport_settings );
     721                $breakpoints = self::sanitize_viewport_settings( $viewport_settings );
    722722
    723723                $responsive_media_queries = array();
     
    789789         */
    790790        private static function get_viewport_breakpoint_value_in_pixels( $value ) {
    791                 if ( ! static::is_valid_viewport_breakpoint_size( $value ) ) {
     791                if ( ! self::is_valid_viewport_breakpoint_size( $value ) ) {
    792792                        return null;
    793793                }
     
    832832                foreach ( array_keys( static::DEFAULT_VIEWPORT_BREAKPOINTS ) as $breakpoint ) {
    833833                        $value = $viewport_settings[ $breakpoint ] ?? null;
    834                         $px    = static::get_viewport_breakpoint_value_in_pixels( $value );
     834                        $px    = self::get_viewport_breakpoint_value_in_pixels( $value );
    835835                        if ( null !== $px ) {
    836836                                $breakpoints[ $breakpoint ] = array(
     
    990990                                if ( is_array( $block_metadata ) ) {
    991991                                        $feature_declarations = $this->get_feature_declarations_for_node( $block_metadata, $pseudo_node );
    992                                         $feature_declarations = static::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
    993                                         $feature_declarations = static::update_button_width_declarations( $feature_declarations, $settings );
     992                                        $feature_declarations = self::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
     993                                        $feature_declarations = self::update_button_width_declarations( $feature_declarations, $settings );
    994994
    995995                                        foreach ( $feature_declarations as $feature_selector => $declarations ) {
     
    10991099                $valid_element_names = array_keys( static::ELEMENTS );
    11001100                $valid_variations    = static::get_valid_block_style_variations( $blocks_metadata );
    1101                 $this->theme_json    = static::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations );
     1101                $this->theme_json    = self::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations );
    11021102                $this->theme_json    = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations );
    11031103                $this->theme_json    = static::maybe_opt_in_into_settings( $this->theme_json );
     
    11371137                        $sizes_path           = array( 'settings', 'spacing', 'spacingSizes', $origin );
    11381138                        $spacing_sizes        = _wp_array_get( $this->theme_json, $sizes_path, array() );
    1139                         $spacing_scale_sizes  = static::compute_spacing_sizes( $spacing_scale );
    1140                         $merged_spacing_sizes = static::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes );
     1139                        $spacing_scale_sizes  = self::compute_spacing_sizes( $spacing_scale );
     1140                        $merged_spacing_sizes = self::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes );
    11411141                        _wp_array_set( $this->theme_json, $sizes_path, $merged_spacing_sizes );
    11421142                }
     
    14581458
    14591459                        if ( 'settings' === $subtree && array_key_exists( 'viewport', $input[ $subtree ] ) ) {
    1460                                 $result['viewport'] = static::sanitize_viewport_settings( $input[ $subtree ]['viewport'] );
     1460                                $result['viewport'] = self::sanitize_viewport_settings( $input[ $subtree ]['viewport'] );
    14611461                        }
    14621462
     
    14641464                                unset( $output[ $subtree ] );
    14651465                        } else {
    1466                                 $output[ $subtree ] = static::resolve_custom_css_format( $result );
     1466                                $output[ $subtree ] = self::resolve_custom_css_format( $result );
    14671467                        }
    14681468                }
     
    25102510                                }
    25112511
    2512                                 $target = static::get_feature_selector( $feature_selectors, $preset_metadata['path'][0], $selector );
     2512                                $target = self::get_feature_selector( $feature_selectors, $preset_metadata['path'][0], $selector );
    25132513
    25142514                                if ( ! isset( $vars_by_selector[ $target ] ) ) {
     
    33083308                }
    33093309
    3310                 $block_nodes = static::get_block_nodes( $theme_json, $selectors, $options );
     3310                $block_nodes = self::get_block_nodes( $theme_json, $selectors, $options );
    33113311                foreach ( $block_nodes as $block_node ) {
    33123312                        $nodes[] = $block_node;
     
    33333333         */
    33343334        public function get_styles_block_nodes() {
    3335                 return static::get_block_nodes( $this->theme_json );
     3335                return self::get_block_nodes( $this->theme_json );
    33363336        }
    33373337
     
    38253825                // Update text indent selector for paragraph blocks based on the textIndent setting.
    38263826                $block_name           = $block_metadata['name'] ?? null;
    3827                 $feature_declarations = static::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
     3827                $feature_declarations = self::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
    38283828                $block_elements       = $block_metadata['elements'] ?? array();
    38293829
    38303830                // Update button width declarations for percentage values to use calc() with block gap.
    3831                 $feature_declarations = static::update_button_width_declarations( $feature_declarations, $settings );
     3831                $feature_declarations = self::update_button_width_declarations( $feature_declarations, $settings );
    38323832
    38333833                // If there are style variations, generate the declarations for them, including any feature selectors the block may have.
     
    38453845
    38463846                                // Update text indent selector for paragraph blocks based on the textIndent setting.
    3847                                 $variation_declarations = static::update_paragraph_text_indent_selector( $variation_declarations, $settings, $block_name );
     3847                                $variation_declarations = self::update_paragraph_text_indent_selector( $variation_declarations, $settings, $block_name );
    38483848
    38493849                                // Update button width declarations for percentage values to use calc() with block gap.
    3850                                 $variation_declarations = static::update_button_width_declarations( $variation_declarations, $settings );
     3850                                $variation_declarations = self::update_button_width_declarations( $variation_declarations, $settings );
    38513851
    38523852                                // Combine selectors with style variation's selector and add to overall style variation declarations.
     
    38653865                                        $block_name = $block_metadata['name'];
    38663866                                } elseif ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ) {
    3867                                         $block_name = static::get_block_name_from_metadata_path( $block_metadata );
     3867                                        $block_name = self::get_block_name_from_metadata_path( $block_metadata );
    38683868                                } else {
    38693869                                        $block_name = null;
     
    39033903                                        // Process feature-level declarations for this breakpoint.
    39043904                                        $breakpoint_feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $breakpoint_node );
    3905                                         $breakpoint_feature_declarations = static::update_paragraph_text_indent_selector( $breakpoint_feature_declarations, $settings, $block_name );
    3906                                         $breakpoint_feature_declarations = static::update_button_width_declarations( $breakpoint_feature_declarations, $settings );
     3905                                        $breakpoint_feature_declarations = self::update_paragraph_text_indent_selector( $breakpoint_feature_declarations, $settings, $block_name );
     3906                                        $breakpoint_feature_declarations = self::update_button_width_declarations( $breakpoint_feature_declarations, $settings );
    39073907                                        foreach ( $breakpoint_feature_declarations as $feature_selector => $feature_decl ) {
    39083908                                                $combined_selectors = static::get_block_style_variation_feature_selector( $style_variation, $feature_selector );
     
    41024102                // Update declarations if there are separators with only background color defined.
    41034103                if ( '.wp-block-separator' === $selector ) {
    4104                         $declarations = static::update_separator_declarations( $declarations );
     4104                        $declarations = self::update_separator_declarations( $declarations );
    41054105                }
    41064106
     
    43444344                        $sizes_path           = array( 'settings', 'spacing', 'spacingSizes', $origin );
    43454345                        $spacing_sizes        = _wp_array_get( $incoming_data, $sizes_path, array() );
    4346                         $spacing_scale_sizes  = static::compute_spacing_sizes( $flattened_spacing_scale );
    4347                         $merged_spacing_sizes = static::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes );
     4346                        $spacing_scale_sizes  = self::compute_spacing_sizes( $flattened_spacing_scale );
     4347                        $merged_spacing_sizes = self::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes );
    43484348
    43494349                        _wp_array_set( $incoming_data, $sizes_path, $merged_spacing_sizes );
     
    44424442                 * objects and represent unique definitions for the style.
    44434443                 */
    4444                 $style_nodes = static::get_block_nodes(
     4444                $style_nodes = self::get_block_nodes(
    44454445                        $this->theme_json,
    44464446                        array(),
     
    46824682
    46834683                        $block_name = in_array( 'blocks', $metadata['path'], true )
    4684                                 ? static::get_block_name_from_metadata_path( $metadata )
     4684                                ? self::get_block_name_from_metadata_path( $metadata )
    46854685                                : null;
    46864686
     
    50095009
    50105010                // Ensure indirect properties not included in any `PRESETS_METADATA` value are allowed.
    5011                 static::remove_indirect_properties( $input, $output );
     5011                self::remove_indirect_properties( $input, $output );
    50125012
    50135013                // Preserve all valid settings that have type markers in VALID_SETTINGS.
     
    50155015
    50165016                if ( $is_root && array_key_exists( 'viewport', $input ) ) {
    5017                         $output['viewport'] = static::sanitize_viewport_settings( $input['viewport'] );
     5017                        $output['viewport'] = self::sanitize_viewport_settings( $input['viewport'] );
    50185018                }
    50195019
     
    50505050
    50515051                // Ensure indirect properties not handled by `compute_style_properties` are allowed.
    5052                 static::remove_indirect_properties( $input, $output );
     5052                self::remove_indirect_properties( $input, $output );
    50535053
    50545054                return $output;
     
    53835383                }
    53845384
    5385                 $spacing_sizes = static::compute_spacing_sizes( $spacing_scale );
     5385                $spacing_sizes = self::compute_spacing_sizes( $spacing_scale );
    53865386
    53875387                // If there are 7 or fewer steps in the scale revert to numbers for labels instead of t-shirt sizes.
     
    54355435         *         'increment'  => 2,
    54365436         *     );
    5437          *     $spacing_sizes = static::compute_spacing_sizes( $spacing_scale );
     5437         *     $spacing_sizes = self::compute_spacing_sizes( $spacing_scale );
    54385438         *     // -> array(
    54395439         *     //        array( 'name' => 'Small',   'slug' => '40', 'size' => '14px' ),
Note: See TracChangeset for help on using the changeset viewer.