From a36a72b486f598b35b023ef9cbe29d98b24d8c1c Mon Sep 17 00:00:00 2001 From: Tyler Stokes Date: Sun, 16 Aug 2026 14:53:23 -0700 Subject: [PATCH] Code Quality: Remove three redundant boolean sub-expressions. Each of these conditions re-tests something the surrounding expression has already established. In `wp_render_typography_support()`, `! empty( $block['attrs']['fitText'] )` already requires the value to be truthy, so the following `&& $block['attrs']['fitText']` can never fail. In `_get_block_templates_files()`, the right operand of the `||` is only evaluated when `! $post_type` was false, so the leading `$post_type &&` is likewise always true. In `Walker::display_element()`, `$newlevel` is a local assigned the literal `true` and nothing else, so `isset( $newlevel ) && $newlevel` reduces to the `isset()`. All three are simplifications with no change in behaviour. This resolves two `booleanAnd.rightAlwaysTrue` and one `booleanAnd.leftAlwaysTrue` occurrence. The baselines were regenerated with: {{{ composer phpstan:baselines -- --identifier=booleanAnd.rightAlwaysTrue,booleanAnd.leftAlwaysTrue }}} Props tstokes8040. See #65817. --- src/wp-includes/block-supports/typography.php | 2 +- src/wp-includes/block-template-utils.php | 2 +- src/wp-includes/class-wp-walker.php | 2 +- tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon | 5 ----- .../phpstan/baselines/booleanAnd.rightAlwaysTrue.neon | 10 ---------- 5 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index 6573119933721..9b4cf151b4a23 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -304,7 +304,7 @@ function wp_typography_get_preset_inline_style_value( $style_value, $css_propert * @return string Filtered block content. */ function wp_render_typography_support( $block_content, $block ) { - if ( ! empty( $block['attrs']['fitText'] ) && $block['attrs']['fitText'] && ! is_admin() ) { + if ( ! empty( $block['attrs']['fitText'] ) && ! is_admin() ) { wp_enqueue_script_module( '@wordpress/block-editor/utils/fit-text-frontend' ); // Add Interactivity API directives for fit text to work with client-side navigation. diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index a7d5d4aa1141d..f77303f5917cd 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -460,7 +460,7 @@ function _get_block_templates_files( $template_type, $query = array() ) { if ( ! $post_type || - ( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) ) + ( isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) ) ) { $template_files[ $template_slug ] = $candidate; } diff --git a/src/wp-includes/class-wp-walker.php b/src/wp-includes/class-wp-walker.php index 7361520cbdccc..3937d5b89dff4 100644 --- a/src/wp-includes/class-wp-walker.php +++ b/src/wp-includes/class-wp-walker.php @@ -164,7 +164,7 @@ public function display_element( $element, &$children_elements, $max_depth, $dep unset( $children_elements[ $id ] ); } - if ( isset( $newlevel ) && $newlevel ) { + if ( isset( $newlevel ) ) { // End the child delimiter. $this->end_lvl( $output, $depth, ...array_values( $args ) ); } diff --git a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon index c64a48177e085..69e4b48b16039 100644 --- a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon +++ b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon @@ -28,11 +28,6 @@ parameters: identifier: booleanAnd.leftAlwaysTrue count: 1 path: ../../../src/wp-admin/themes.php - - - message: '#^Left side of && is always true\.$#' - identifier: booleanAnd.leftAlwaysTrue - count: 1 - path: ../../../src/wp-includes/block-template-utils.php - message: '#^Left side of && is always true\.$#' identifier: booleanAnd.leftAlwaysTrue diff --git a/tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon b/tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon index 64071efcf3d23..a74e9d89d9fd2 100644 --- a/tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon +++ b/tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon @@ -33,16 +33,6 @@ parameters: identifier: booleanAnd.rightAlwaysTrue count: 1 path: ../../../src/wp-content/themes/twentynineteen/header.php - - - message: '#^Right side of && is always true\.$#' - identifier: booleanAnd.rightAlwaysTrue - count: 1 - path: ../../../src/wp-includes/block-supports/typography.php - - - message: '#^Right side of && is always true\.$#' - identifier: booleanAnd.rightAlwaysTrue - count: 1 - path: ../../../src/wp-includes/class-wp-walker.php - message: '#^Right side of && is always true\.$#' identifier: booleanAnd.rightAlwaysTrue