Skip to content

Commit 87e64ab

Browse files
committed
Code Quality: Remove always-true strict comparisons.
PHPStan reports these conditions as always true (`notIdentical.alwaysTrue`), so they are simplified and the matching entries are removed from the PHPStan baseline: * In `WP_Links_List_Table::prepare_items()`, `$cat_id` is compared with `0` instead of `'all'`. Since r58069 it has always been an integer from `absint()`, so the string comparison could never fail. An empty category was already ignored by `get_bookmarks()`. * In `wp_get_layout_style()`, the flex layout's `$gap_value` is checked against an empty string instead of `null`, since it is always the string result of `trim()`. The style engine already drops empty declarations, so the CSS output is unchanged. * In `WP_Rewrite::add_rewrite_tag()` and `WP_Rewrite::remove_rewrite_tag()`, the redundant `null` check is removed, since `array_search()` returns either a key or `false`. Developed in #13670. Follow-up to r36217, r54274, r58069, r63023. Props arshidkv12, westonruter. See #65817. Fixes #66155. git-svn-id: https://develop.svn.wordpress.org/trunk@63887 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9b621ad commit 87e64ab

4 files changed

Lines changed: 4 additions & 19 deletions

File tree

‎src/wp-admin/includes/class-wp-links-list-table.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function prepare_items() {
6060
'hide_empty' => 0,
6161
);
6262

63-
if ( 'all' !== $cat_id ) {
63+
if ( 0 !== $cat_id ) {
6464
$args['category'] = $cat_id;
6565
}
6666
if ( ! empty( $s ) ) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
780780
}
781781
$gap_value = trim( $combined_gap_value );
782782

783-
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
783+
if ( '' !== $gap_value && ! $should_skip_gap_serialization ) {
784784
$layout_styles[] = array(
785785
'selector' => $selector,
786786
'declarations' => array( 'gap' => $gap_value ),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public function get_comment_feed_permastruct() {
799799
*/
800800
public function add_rewrite_tag( $tag, $regex, $query ) {
801801
$position = array_search( $tag, $this->rewritecode, true );
802-
if ( false !== $position && null !== $position ) {
802+
if ( false !== $position ) {
803803
$this->rewritereplace[ $position ] = $regex;
804804
$this->queryreplace[ $position ] = $query;
805805
} else {
@@ -823,7 +823,7 @@ public function add_rewrite_tag( $tag, $regex, $query ) {
823823
*/
824824
public function remove_rewrite_tag( $tag ) {
825825
$position = array_search( $tag, $this->rewritecode, true );
826-
if ( false !== $position && null !== $position ) {
826+
if ( false !== $position ) {
827827
unset( $this->rewritecode[ $position ] );
828828
unset( $this->rewritereplace[ $position ] );
829829
unset( $this->queryreplace[ $position ] );

‎tests/phpstan/baselines/notIdentical.alwaysTrue.neon‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,6 @@
1818

1919
parameters:
2020
ignoreErrors:
21-
-
22-
message: '#^Strict comparison using \!\=\= between ''all'' and int will always evaluate to true\.$#'
23-
identifier: notIdentical.alwaysTrue
24-
count: 1
25-
path: ../../../src/wp-admin/includes/class-wp-links-list-table.php
26-
-
27-
message: '#^Strict comparison using \!\=\= between null and string will always evaluate to true\.$#'
28-
identifier: notIdentical.alwaysTrue
29-
count: 1
30-
path: ../../../src/wp-includes/block-supports/layout.php
31-
-
32-
message: '#^Strict comparison using \!\=\= between null and int\|string will always evaluate to true\.$#'
33-
identifier: notIdentical.alwaysTrue
34-
count: 2
35-
path: ../../../src/wp-includes/class-wp-rewrite.php
3621
-
3722
message: '#^Strict comparison using \!\=\= between ''Etc'' and ''Africa''\|''America''\|''Antarctica''\|''Arctic''\|''Asia''\|''Atlantic''\|''Australia''\|''Europe''\|''Indian''\|''Pacific'' will always evaluate to true\.$#'
3823
identifier: notIdentical.alwaysTrue

0 commit comments

Comments
 (0)