Skip to content

Commit b563f87

Browse files
committed
More improvements
1 parent 9799ea8 commit b563f87

12 files changed

+32
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"wp-cli/extension-command": "^1.2 || ^2",
2121
"wp-cli/media-command": "^1.1 || ^2",
2222
"wp-cli/super-admin-command": "^1 || ^2",
23-
"wp-cli/wp-cli-tests": "dev-main"
23+
"wp-cli/wp-cli-tests": "dev-add/phpstan-enhancements"
2424
},
2525
"config": {
2626
"process-timeout": 7200,

phpstan.neon.dist

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 9
33
paths:
44
- src
55
- entity-command.php
@@ -9,10 +9,6 @@ parameters:
99
scanFiles:
1010
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
1111
treatPhpDocTypesAsCertain: false
12-
dynamicConstantNames:
13-
- WP_DEBUG
14-
- WP_DEBUG_LOG
15-
- WP_DEBUG_DISPLAY
1612
ignoreErrors:
1713
- identifier: missingType.iterableValue
1814
- identifier: missingType.property

src/Comment_Command.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,12 @@ public function list_( $args, $assoc_args ) {
387387
* @var int $comments
388388
*/
389389
echo $comments;
390+
return;
390391
} else {
392+
/**
393+
* @var array $comments
394+
*/
395+
391396
if ( 'ids' === $formatter->format ) {
392397
/**
393398
* @var \WP_Comment[] $comments

src/Comment_Meta_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) {
104104
/**
105105
* Check that the comment ID exists
106106
*
107-
* @param int $object_id
107+
* @param string|int $object_id
108+
* @return int|never
108109
*/
109110
protected function check_object_id( $object_id ) {
110111
$fetcher = new CommentFetcher();

src/Option_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ public function add( $args, $assoc_args ) {
241241
* Success: Deleted 'theme_mods_twentyfourteen' option.
242242
*
243243
* @subcommand list
244+
*
245+
* @param string[] $args Positional arguments. Unused.
246+
* @param array{search?: string, exclude: string, autoload: string, transients?: bool, unserialize?: bool, field?: string, fields: string, format: 'table'|'csv'|'json'|'yaml'|'count'|'total_bytes', orderby: 'option_id'|'option_name'|'option_value', order: 'asc'|'desc'} $assoc_args Associative arguments.
244247
*/
245248
public function list_( $args, $assoc_args ) {
246249

src/Post_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,9 @@ private function get_category_ids( $arg ) {
974974
* @return array
975975
*/
976976
private function get_metadata( $post_id ) {
977+
/**
978+
* @var array<string, array<string>> $metadata
979+
*/
977980
$metadata = get_metadata( 'post', $post_id );
978981
$items = [];
979982
foreach ( $metadata as $key => $values ) {

src/Post_Meta_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class Post_Meta_Command extends CommandWithMeta {
3030
/**
3131
* Check that the post ID exists
3232
*
33-
* @param int $object_id
33+
* @param string|int $object_id
34+
* @return int|never
3435
*/
3536
protected function check_object_id( $object_id ) {
3637
$fetcher = new PostFetcher();

src/Site_Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ private function insert_default_terms() {
164164
/* translators: Default category slug */
165165
$cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
166166

167-
// phpcs:ignore WordPress.WP.DeprecatedFunctions.global_terms_enabledFound -- Required for backwards compatibility.
168-
if ( global_terms_enabled() ) {
167+
// @phpstan-ignore function.deprecated
168+
if ( global_terms_enabled() ) { // phpcs:ignore WordPress.WP.DeprecatedFunctions.global_terms_enabledFound -- Required for backwards compatibility.
169169
$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
170170
if ( null === $cat_id ) {
171171
$wpdb->insert(

src/Site_Meta_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class Site_Meta_Command extends CommandWithMeta {
3030
/**
3131
* Check that the site ID exists
3232
*
33-
* @param int $object_id
33+
* @param string|int $object_id
34+
* @return int|never
3435
*/
3536
protected function check_object_id( $object_id ) {
3637
$fetcher = new SiteFetcher();

src/Term_Meta_Command.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class Term_Meta_Command extends CommandWithMeta {
2929
/**
3030
* Check that the term ID exists
3131
*
32-
* @param int $object_id
32+
* @param string|int $object_id
33+
* @return int|never
3334
*/
3435
protected function check_object_id( $object_id ) {
35-
$term = get_term( $object_id );
36+
$term = get_term( (int) $object_id );
3637
if ( ! $term || is_wp_error( $term ) ) {
3738
WP_CLI::error( "Could not find the term with ID {$object_id}." );
3839
}

0 commit comments

Comments
 (0)