Skip to content

Commit ea146ac

Browse files
committed
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 #13086. Follow-up to r55687, r61246, r63023. Props tstokes8040. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@63542 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 40a1782 commit ea146ac

5 files changed

Lines changed: 3 additions & 18 deletions

File tree

‎src/wp-includes/block-supports/typography.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function wp_typography_get_preset_inline_style_value( $style_value, $css_propert
304304
* @return string Filtered block content.
305305
*/
306306
function 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

310310
// Add Interactivity API directives for fit text to work with client-side navigation.

‎src/wp-includes/block-template-utils.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ function _get_block_templates_files( $template_type, $query = array() ) {
459459

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;
465465
}

‎src/wp-includes/class-wp-walker.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function display_element( $element, &$children_elements, $max_depth, $dep
164164
unset( $children_elements[ $id ] );
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 ) );
170170
}

‎tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ parameters:
2828
identifier: booleanAnd.leftAlwaysTrue
2929
count: 1
3030
path: ../../../src/wp-admin/themes.php
31-
-
32-
message: '#^Left side of && is always true\.$#'
33-
identifier: booleanAnd.leftAlwaysTrue
34-
count: 1
35-
path: ../../../src/wp-includes/block-template-utils.php
3631
-
3732
message: '#^Left side of && is always true\.$#'
3833
identifier: booleanAnd.leftAlwaysTrue

‎tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ parameters:
2828
identifier: booleanAnd.rightAlwaysTrue
2929
count: 1
3030
path: ../../../src/wp-content/themes/twentynineteen/header.php
31-
-
32-
message: '#^Right side of && is always true\.$#'
33-
identifier: booleanAnd.rightAlwaysTrue
34-
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
4131
-
4232
message: '#^Right side of && is always true\.$#'
4333
identifier: booleanAnd.rightAlwaysTrue

0 commit comments

Comments
 (0)