Make WordPress Core

Changeset 63542


Ignore:
Timestamp:
09/08/2026 08:05:22 PM (5 days ago)
Author:
westonruter
Message:

Code Quality: Remove redundant boolean sub-expressions.

Each of three conditions re-tests something the surrounding expression has already established, so PHPStan reports the redundant operand as always true:

  1. In wp_render_typography_support(), ! empty() already requires the fitText attribute to be truthy, so a following truthiness check on the same value can never fail.
  2. In _get_block_templates_files(), the right operand of an || is only evaluated when ! $post_type was false, so a leading $post_type && there is always true.
  3. In Walker::display_element(), $newlevel is a local variable that is only ever assigned the literal true, so the truthiness test adds nothing to the isset().

All three are simplifications with no change in behavior. This resolves two booleanAnd.rightAlwaysTrue occurrences and one booleanAnd.leftAlwaysTrue occurrence, and the corresponding PHPStan baselines are regenerated.

Developed in https://github.com/WordPress/wordpress-develop/pull/13086.
Follow-up to r55687, r61246, r63023.

Props tstokes8040.
See #65817.

Location:
trunk
Files:
5 edited

Legend:

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

    r63382 r63542  
    305305 */
    306306function wp_render_typography_support( $block_content, $block ) {
    307         if ( ! empty( $block['attrs']['fitText'] ) && $block['attrs']['fitText'] && ! is_admin() ) {
     307        if ( ! empty( $block['attrs']['fitText'] ) && ! is_admin() ) {
    308308                wp_enqueue_script_module( '@wordpress/block-editor/utils/fit-text-frontend' );
    309309
  • trunk/src/wp-includes/block-template-utils.php

    r63495 r63542  
    460460                                if (
    461461                                        ! $post_type ||
    462                                         ( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
     462                                        ( isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
    463463                                ) {
    464464                                        $template_files[ $template_slug ] = $candidate;
  • trunk/src/wp-includes/class-wp-walker.php

    r62695 r63542  
    165165                }
    166166
    167                 if ( isset( $newlevel ) && $newlevel ) {
     167                if ( isset( $newlevel ) ) {
    168168                        // End the child delimiter.
    169169                        $this->end_lvl( $output, $depth, ...array_values( $args ) );
  • trunk/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon

    r63023 r63542  
    3333                        identifier: booleanAnd.leftAlwaysTrue
    3434                        count: 1
    35                         path: ../../../src/wp-includes/block-template-utils.php
    36                 -
    37                         message: '#^Left side of && is always true\.$#'
    38                         identifier: booleanAnd.leftAlwaysTrue
    39                         count: 1
    4035                        path: ../../../src/wp-includes/canonical.php
    4136                -
  • trunk/tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon

    r63356 r63542  
    3333                        identifier: booleanAnd.rightAlwaysTrue
    3434                        count: 1
    35                         path: ../../../src/wp-includes/block-supports/typography.php
    36                 -
    37                         message: '#^Right side of && is always true\.$#'
    38                         identifier: booleanAnd.rightAlwaysTrue
    39                         count: 1
    40                         path: ../../../src/wp-includes/class-wp-walker.php
    41                 -
    42                         message: '#^Right side of && is always true\.$#'
    43                         identifier: booleanAnd.rightAlwaysTrue
    44                         count: 1
    4535                        path: ../../../src/wp-includes/functions.php
Note: See TracChangeset for help on using the changeset viewer.