-
Notifications
You must be signed in to change notification settings - Fork 94
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 2 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,20 @@ | ||
parameters: | ||
level: 6 | ||
paths: | ||
- src | ||
- entity-command.php | ||
scanDirectories: | ||
- vendor/wp-cli/wp-cli/php | ||
- vendor/wp-cli/wp-cli-tests | ||
scanFiles: | ||
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php | ||
treatPhpDocTypesAsCertain: false | ||
dynamicConstantNames: | ||
- WP_DEBUG | ||
- WP_DEBUG_LOG | ||
- WP_DEBUG_DISPLAY | ||
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 @@ class Menu_Item_Command extends WP_CLI_Command { | |
public function list_( $args, $assoc_args ) { | ||
|
||
$items = wp_get_nav_menu_items( $args[0] ); | ||
if ( false === $items || is_wp_error( $items ) ) { | ||
if ( false === $items ) { | ||
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. Is it impossible here to end up with a 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. 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) |
||
WP_CLI::error( 'Invalid menu.' ); | ||
} | ||
|
||
|
@@ -408,10 +408,10 @@ public function delete( $args, $assoc_args ) { | |
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.' ); | ||
} | ||
|
||
|
@@ -502,7 +502,7 @@ private function add_or_update_item( $method, $type, $args, $assoc_args ) { | |
} | ||
|
||
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 |
---|---|---|
|
@@ -77,6 +77,8 @@ public function list_( $args, $assoc_args ) { | |
|
||
$formatter = new Formatter( $assoc_args, [ 'location', 'description' ] ); | ||
|
||
// To be fixed in wp-cli/wp-cli. | ||
// @phpstan-ignore property.notFound | ||
if ( 'ids' === $formatter->format ) { | ||
$ids = array_map( | ||
function ( $o ) { | ||
|
@@ -107,6 +109,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 +151,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." ); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,10 +182,6 @@ public function create( $args, $assoc_args ) { | |
$assoc_args['post_category'] = $this->get_category_ids( $assoc_args['post_category'] ); | ||
} | ||
|
||
if ( isset( $assoc_args['meta_input'] ) && Utils\wp_version_compare( '4.4', '<' ) ) { | ||
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. Figured with our move to WP 4.9+ we can remove this compat code. |
||
WP_CLI::warning( "The 'meta_input' field was only introduced in WordPress 4.4 so will have no effect." ); | ||
} | ||
|
||
$array_arguments = [ 'meta_input' ]; | ||
$assoc_args = Utils\parse_shell_arrays( $assoc_args, $array_arguments ); | ||
|
||
|
@@ -351,10 +347,6 @@ public function update( $args, $assoc_args ) { | |
$assoc_args['post_category'] = $this->get_category_ids( $assoc_args['post_category'] ); | ||
} | ||
|
||
if ( isset( $assoc_args['meta_input'] ) && Utils\wp_version_compare( '4.4', '<' ) ) { | ||
WP_CLI::warning( "The 'meta_input' field was only introduced in WordPress 4.4 so will have no effect." ); | ||
} | ||
|
||
$array_arguments = [ 'meta_input' ]; | ||
$assoc_args = Utils\parse_shell_arrays( $assoc_args, $array_arguments ); | ||
|
||
|
@@ -387,7 +379,7 @@ public function edit( $args, $assoc_args ) { | |
$result = $this->_edit( $post->post_content, "WP-CLI post {$post->ID}" ); | ||
|
||
if ( false === $result ) { | ||
WP_CLI::warning( 'No change made to post content.', 'Aborted' ); | ||
WP_CLI::warning( 'No change made to post content.' ); | ||
} else { | ||
$this->update( $args, [ 'post_content' => $result ] ); | ||
} | ||
|
@@ -644,9 +636,12 @@ public function list_( $args, $assoc_args ) { | |
$query_args['post_type'] = explode( ',', $query_args['post_type'] ); | ||
} | ||
|
||
// To be fixed in wp-cli/wp-cli. | ||
// @phpstan-ignore property.notFound | ||
if ( 'ids' === $formatter->format ) { | ||
$query_args['fields'] = 'ids'; | ||
$query = new WP_Query( $query_args ); | ||
// @phpstan-ignore argument.type | ||
echo implode( ' ', $query->posts ); | ||
} elseif ( 'count' === $formatter->format ) { | ||
$query_args['fields'] = 'ids'; | ||
|
@@ -656,8 +651,13 @@ public function list_( $args, $assoc_args ) { | |
$query = new WP_Query( $query_args ); | ||
$posts = array_map( | ||
function ( $post ) { | ||
$post->url = get_permalink( $post->ID ); | ||
return $post; | ||
/** | ||
* @var \WP_Post $post | ||
*/ | ||
|
||
// @phpstan-ignore property.notFound | ||
$post->url = get_permalink( $post->ID ); | ||
return $post; | ||
}, | ||
$query->posts | ||
); | ||
|
Uh oh!
There was an error while loading. Please reload this page.