-
Notifications
You must be signed in to change notification settings - Fork 95
PHPStan level 9 #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
PHPStan level 9 #536
Changes from all commits
d8c60d0
db4f48e
99de66c
cd773ae
9785355
9799ea8
b563f87
062a74b
15156af
7b6bde6
f2f3a25
cf1a611
ab1d4b6
7b63c26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
parameters: | ||
level: 9 | ||
paths: | ||
- src | ||
- entity-command.php | ||
scanDirectories: | ||
- vendor/wp-cli/wp-cli/php | ||
scanFiles: | ||
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php | ||
treatPhpDocTypesAsCertain: false | ||
ignoreErrors: | ||
- identifier: missingType.iterableValue | ||
- identifier: missingType.property | ||
- identifier: missingType.parameter | ||
- identifier: missingType.return |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ | |
public function list_( $args, $assoc_args ) { | ||
|
||
$items = wp_get_nav_menu_items( $args[0] ); | ||
if ( false === $items || is_wp_error( $items ) ) { | ||
if ( false === $items ) { | ||
WP_CLI::error( 'Invalid menu.' ); | ||
} | ||
|
||
|
@@ -367,8 +367,10 @@ | |
|
||
foreach ( $args as $arg ) { | ||
|
||
$post = get_post( $arg ); | ||
$menu_term = get_the_terms( $arg, 'nav_menu' ); | ||
$post = get_post( $arg ); | ||
$menu_term = get_the_terms( $arg, 'nav_menu' ); | ||
|
||
// @phpstan-ignore cast.int | ||
$parent_menu_id = (int) get_post_meta( $arg, '_menu_item_menu_item_parent', true ); | ||
$result = wp_delete_post( $arg, true ); | ||
if ( ! $result ) { | ||
|
@@ -408,10 +410,10 @@ | |
private function add_or_update_item( $method, $type, $args, $assoc_args ) { | ||
|
||
$menu = $args[0]; | ||
$menu_item_db_id = Utils\get_flag_value( $args, 1, 0 ); | ||
$menu_item_db_id = $args[1] ?? 0; | ||
|
||
$menu = wp_get_nav_menu_object( $menu ); | ||
if ( ! $menu || is_wp_error( $menu ) ) { | ||
if ( false === $menu ) { | ||
Comment on lines
-414
to
+416
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here re. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. It was originally introduced in 246a8bc, but without any test coverage or so. Like in the other cases, this function never returns a |
||
WP_CLI::error( 'Invalid menu.' ); | ||
} | ||
|
||
|
@@ -422,6 +424,14 @@ | |
if ( 'update' === $method ) { | ||
|
||
$menu_item_obj = get_post( $menu_item_db_id ); | ||
|
||
if ( ! $menu_item_obj ) { | ||
WP_CLI::error( 'Invalid menu.' ); | ||
} | ||
|
||
/** | ||
* @var object{title: string, url: string, description: string, object: string, object_id: int, menu_item_parent: int, attr_title: string, target: string, classes: string[], xfn: string, post_status: string, menu_order: int} $menu_item_obj | ||
*/ | ||
$menu_item_obj = wp_setup_nav_menu_item( $menu_item_obj ); | ||
|
||
// Correct the menu position if this was the first item. See https://core.trac.wordpress.org/ticket/28140 | ||
|
@@ -502,7 +512,7 @@ | |
} | ||
|
||
if ( 'add' === $method && ! empty( $assoc_args['porcelain'] ) ) { | ||
WP_CLI::line( $result ); | ||
WP_CLI::line( (string) $result ); | ||
} elseif ( 'add' === $method ) { | ||
WP_CLI::success( 'Menu item added.' ); | ||
} elseif ( 'update' === $method ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,8 @@ function ( $o ) { | |
* Success: Assigned location primary to menu primary-menu. | ||
* | ||
* @subcommand assign | ||
* | ||
* @param array{string, string} $args | ||
*/ | ||
public function assign( $args, $assoc_args ) { | ||
|
||
|
@@ -147,18 +149,20 @@ public function assign( $args, $assoc_args ) { | |
* Success: Removed location from menu. | ||
* | ||
* @subcommand remove | ||
* | ||
* @param array{string, string} $args | ||
*/ | ||
public function remove( $args, $assoc_args ) { | ||
|
||
list( $menu, $location ) = $args; | ||
|
||
$menu = wp_get_nav_menu_object( $menu ); | ||
if ( ! $menu || is_wp_error( $menu ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here re. |
||
if ( false === $menu ) { | ||
WP_CLI::error( 'Invalid menu.' ); | ||
} | ||
|
||
$locations = get_nav_menu_locations(); | ||
if ( Utils\get_flag_value( $locations, $location ) !== $menu->term_id ) { | ||
if ( ( $locations[ $location ] ?? null ) !== $menu->term_id ) { | ||
WP_CLI::error( "Menu isn't assigned to location." ); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it impossible here to end up with a
WP_Error
? Relying on the docblocks is not enough, and I'm seeing that multiple filters are involved... 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no code path in there that returns WP_Error, I already checked.
Filters can always be abused, but we can‘t check for every possible return value.
git blame was unfortunately not helpful here (mangled history)