Make WordPress Core


Ignore:
Timestamp:
10/26/2026 02:17:56 AM (2 days ago)
Author:
westonruter
Message:

Code Quality: Sync PHPStan fixes from Gutenberg.

These fixes were made in Gutenberg while resolving the PHPStan errors in the plugin, ahead of adding PHPStan to its CI, and are brought to core to keep the two codebases in sync. They were developed in:

The first one fixes a bug in core. Since r56046 the array_key_exists() checks in wp_register_shadow_support() have lacked their negation, so a block type with shadow support but no style or shadow attribute never had them registered, while one that already defined them had its definitions replaced, dropping any default. Gutenberg already had the negation. Tests are added for the attribute registration.

The others make implicit type conversions explicit in the layout and duotone code, and narrow the types used by WP_Theme_JSON::get_feature_declarations_for_node() so that it reports no errors even at PHPStan rule level 10. Since the node comes from theme.json data, that method now also checks that a feature is an array before reading its subfeatures. This fixes a fatal error ("Cannot unset string offsets") when a feature's value is a string, such as a shadow, and the block's selectors for that feature are a list rather than keyed by subfeature name, since each numeric key then reads a character of the string instead of a subfeature. The baseline entries for the resolved errors are removed.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14862.
Follow-up to r56046, r56058, r56101, r62478, r63426.

Props justlevine, westonruter, poena, ramonopoly.
See #65817.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/shadow.php

    r63529 r64727  
    2626        }
    2727
    28         if ( array_key_exists( 'style', $block_type->attributes ) ) {
     28        if ( ! array_key_exists( 'style', $block_type->attributes ) ) {
    2929                $block_type->attributes['style'] = array(
    3030                        'type' => 'object',
    … …  
    3232        }
    3333
    34         if ( array_key_exists( 'shadow', $block_type->attributes ) ) {
     34        if ( ! array_key_exists( 'shadow', $block_type->attributes ) ) {
    3535                $block_type->attributes['shadow'] = array(
    3636                        'type' => 'string',
Note: See TracChangeset for help on using the changeset viewer.