Skip to content

Commit bfd3f97

Browse files
PHPStan: Retire booleanAnd.alwaysFalse baseline
- In src/wp-admin/themes.php, line 128 statically sets $parent_file = 'themes.php'. Therefore, empty( $parent_file ) is always false. Simplify the current menu item check to $item[2] === $parent_file. - In src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php, $schema was used in update_item() without being assigned, causing $schema['properties']['featured_media'] to always evaluate to empty/false and generating an undefined variable notice. Initialize $schema = $this->get_item_schema(); as done in create_item(). - Regenerate PHPStan baselines to delete tests/phpstan/baselines/booleanAnd.alwaysFalse.neon and update phpstan.neon.dist.
1 parent dcd149a commit bfd3f97

7 files changed

Lines changed: 2 additions & 54 deletions

File tree

‎phpstan.neon.dist‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ includes:
2727
- tests/phpstan/baselines/arrayValues.list.neon
2828
- tests/phpstan/baselines/assign.propertyType.neon
2929
- tests/phpstan/baselines/binaryOp.invalid.neon
30-
- tests/phpstan/baselines/booleanAnd.alwaysFalse.neon
3130
- tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon
3231
- tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon
3332
- tests/phpstan/baselines/booleanNot.alwaysFalse.neon

‎src/wp-admin/themes.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@
373373
}
374374

375375
// 0 = name, 1 = capability, 2 = file.
376-
if ( 0 === strcmp( $self, $item[2] ) && empty( $parent_file )
377-
|| $parent_file && $item[2] === $parent_file
378-
) {
376+
if ( $item[2] === $parent_file ) {
379377
$class = ' current';
380378
}
381379

‎src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ public function update_item( $request ) {
991991
update_post_meta( $data['id'], '_wp_attachment_image_alt', $request['alt_text'] );
992992
}
993993

994+
$schema = $this->get_item_schema();
994995
$attachment = get_post( $request['id'] );
995996

996997
if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) ) {

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ parameters:
2323
identifier: booleanAnd.leftAlwaysTrue
2424
count: 1
2525
path: ../../../src/wp-admin/network/users.php
26-
-
27-
message: '#^Left side of && is always true\.$#'
28-
identifier: booleanAnd.leftAlwaysTrue
29-
count: 1
30-
path: ../../../src/wp-admin/themes.php
3126
-
3227
message: '#^Left side of && is always true\.$#'
3328
identifier: booleanAnd.leftAlwaysTrue

‎tests/phpstan/baselines/empty.variable.neon‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ parameters:
2323
identifier: empty.variable
2424
count: 1
2525
path: ../../../src/wp-admin/includes/class-wp-posts-list-table.php
26-
-
27-
message: '#^Variable \$parent_file in empty\(\) always exists and is not falsy\.$#'
28-
identifier: empty.variable
29-
count: 1
30-
path: ../../../src/wp-admin/themes.php
3126
-
3227
message: '#^Variable \$addl_path in empty\(\) always exists and is always falsy\.$#'
3328
identifier: empty.variable
@@ -43,11 +38,6 @@ parameters:
4338
identifier: empty.variable
4439
count: 1
4540
path: ../../../src/wp-includes/class-wp-query.php
46-
-
47-
message: '#^Variable \$schema in empty\(\) is never defined\.$#'
48-
identifier: empty.variable
49-
count: 1
50-
path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
5141
-
5242
message: '#^Variable \$the_parent in empty\(\) always exists and is not falsy\.$#'
5343
identifier: empty.variable

‎tests/phpstan/baselines/variable.undefined.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,6 @@ parameters:
458458
identifier: variable.undefined
459459
count: 1
460460
path: ../../../src/wp-admin/theme-install.php
461-
-
462-
message: '#^Variable \$self might not be defined\.$#'
463-
identifier: variable.undefined
464-
count: 1
465-
path: ../../../src/wp-admin/themes.php
466461
-
467462
message: '#^Variable \$submenu might not be defined\.$#'
468463
identifier: variable.undefined

0 commit comments

Comments
 (0)