Skip to content

Commit 9785355

Browse files
committed
Almost level 9
1 parent cd773ae commit 9785355

10 files changed

+105
-19
lines changed

src/Comment_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function delete( $args, $assoc_args ) {
435435
$args,
436436
$assoc_args,
437437
function ( $comment_id, $assoc_args ) {
438-
$force = Utils\get_flag_value( $assoc_args, 'force' );
438+
$force = (bool) Utils\get_flag_value( $assoc_args, 'force' );
439439

440440
$status = wp_get_comment_status( $comment_id );
441441
$result = wp_delete_comment( $comment_id, $force );

src/Option_Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,11 @@ public function update( $args, $assoc_args ) {
423423
$autoload = null;
424424
}
425425

426+
/**
427+
* @var string $value
428+
*/
426429
$value = sanitize_option( $key, $value );
430+
427431
// Sanitization WordPress normally performs when getting an option
428432
if ( in_array( $key, [ 'siteurl', 'home', 'category_base', 'tag_base' ], true ) ) {
429433
$value = untrailingslashit( $value );

src/Signup_Command.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,12 @@ public function list_( $args, $assoc_args ) {
130130

131131
$signups = array();
132132

133-
$per_page = (int) Utils\get_flag_value( $assoc_args, 'per_page' );
133+
/**
134+
* @var string|null $per_page
135+
*/
136+
$per_page = Utils\get_flag_value( $assoc_args, 'per_page' );
134137

135-
$limit = $per_page ? $wpdb->prepare( 'LIMIT %d', $per_page ) : '';
138+
$limit = $per_page ? $wpdb->prepare( 'LIMIT %d', (int) $per_page ) : '';
136139

137140
$query = "SELECT * FROM $wpdb->signups {$limit}";
138141

src/Site_Command.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ public function empty_( $args, $assoc_args ) {
283283
$files_to_unlink = [];
284284
$directories_to_delete = [];
285285
$is_main_site = is_main_site();
286+
287+
/**
288+
* @var \SplFileInfo $fileinfo
289+
*/
286290
foreach ( $files as $fileinfo ) {
287291
$realpath = $fileinfo->getRealPath();
288292
// Don't clobber subsites when operating on the main site
@@ -405,7 +409,11 @@ public function create( $args, $assoc_args ) {
405409

406410
global $wpdb, $current_site;
407411

408-
$base = $assoc_args['slug'];
412+
$base = $assoc_args['slug'];
413+
414+
/**
415+
* @var string $title
416+
*/
409417
$title = Utils\get_flag_value( $assoc_args, 'title', ucfirst( $base ) );
410418

411419
$email = empty( $assoc_args['email'] ) ? '' : $assoc_args['email'];
@@ -1203,6 +1211,9 @@ private function update_site_status( $ids, $pref, $value ) {
12031211
* @throws ExitException
12041212
*/
12051213
private function get_sites_ids( $args, $assoc_args ) {
1214+
/**
1215+
* @var string|false $slug
1216+
*/
12061217
$slug = Utils\get_flag_value( $assoc_args, 'slug', false );
12071218

12081219
if ( $slug ) {

src/Term_Command.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,12 @@ public function get( $args, $assoc_args ) {
287287

288288
list( $taxonomy, $term ) = $args;
289289

290-
$term = get_term_by( Utils\get_flag_value( $assoc_args, 'by' ), $term, $taxonomy );
290+
/**
291+
* @var string $field
292+
*/
293+
$field = Utils\get_flag_value( $assoc_args, 'by' );
294+
295+
$term = get_term_by( $field, $term, $taxonomy );
291296

292297
if ( ! $term ) {
293298
WP_CLI::error( "Term doesn't exist." );
@@ -372,7 +377,12 @@ public function update( $args, $assoc_args ) {
372377

373378
$assoc_args = wp_slash( $assoc_args );
374379

375-
$term = get_term_by( Utils\get_flag_value( $assoc_args, 'by' ), $term, $taxonomy );
380+
/**
381+
* @var string $field
382+
*/
383+
$field = Utils\get_flag_value( $assoc_args, 'by' );
384+
385+
$term = get_term_by( $field, $term, $taxonomy );
376386

377387
if ( ! $term ) {
378388
WP_CLI::error( "Term doesn't exist." );
@@ -691,11 +701,23 @@ public function recount( $args ) {
691701
* Success: Migrated the term 'video' from taxonomy 'category' to taxonomy 'post_tag' for 1 post.
692702
*/
693703
public function migrate( $args, $assoc_args ) {
694-
$term_reference = $args[0];
695-
$original_taxonomy = Utils\get_flag_value( $assoc_args, 'from' );
704+
$term_reference = $args[0];
705+
706+
/**
707+
* @var string $original_taxonomy
708+
*/
709+
$original_taxonomy = Utils\get_flag_value( $assoc_args, 'from' );
710+
/**
711+
* @var string $destination_taxonomy
712+
*/
696713
$destination_taxonomy = Utils\get_flag_value( $assoc_args, 'to' );
697714

698-
$term = get_term_by( Utils\get_flag_value( $assoc_args, 'by' ), $term_reference, $original_taxonomy );
715+
/**
716+
* @var string $field
717+
*/
718+
$field = Utils\get_flag_value( $assoc_args, 'by' );
719+
720+
$term = get_term_by( $field, $term_reference, $original_taxonomy );
699721

700722
if ( ! $term ) {
701723
WP_CLI::error( "Taxonomy term '{$term_reference}' for taxonomy '{$original_taxonomy}' doesn't exist." );

src/User_Application_Password_Command.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,23 @@ public function get( $args, $assoc_args ) {
315315
public function create( $args, $assoc_args ) {
316316
$args = $this->replace_login_with_user_id( $args );
317317

318+
/**
319+
* @var string $user_id
320+
* @var string $app_name
321+
*/
318322
list( $user_id, $app_name ) = $args;
319323

324+
/**
325+
* @var string $app_id
326+
*/
320327
$app_id = Utils\get_flag_value( $assoc_args, 'app-id', '' );
321328

322329
$arguments = [
323330
'name' => $app_name,
324331
'app_id' => $app_id,
325332
];
326333

327-
$result = WP_Application_Passwords::create_new_application_password( $user_id, $arguments );
334+
$result = WP_Application_Passwords::create_new_application_password( (int) $user_id, $arguments );
328335

329336
if ( $result instanceof WP_Error ) {
330337
WP_CLI::error( $result );

src/User_Command.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,13 @@ public function get( $args, $assoc_args ) {
283283
* $ wp user delete $(wp user list --role=contributor --field=ID | head -n 100)
284284
*/
285285
public function delete( $args, $assoc_args ) {
286-
$network = Utils\get_flag_value( $assoc_args, 'network' ) && is_multisite();
286+
$network = Utils\get_flag_value( $assoc_args, 'network' ) && is_multisite();
287+
288+
/**
289+
* @var string|null $reassign
290+
*/
287291
$reassign = Utils\get_flag_value( $assoc_args, 'reassign' );
292+
$reassign = (int) $reassign;
288293

289294
if ( $network && $reassign ) {
290295
WP_CLI::error( 'Reassigning content to a different user is not supported on multisite.' );
@@ -982,7 +987,9 @@ public function list_caps( $args, $assoc_args ) {
982987
}
983988
break;
984989
case 'user':
985-
// Get the user's capabilities
990+
/**
991+
* @var array<string, int> $user_capabilities
992+
*/
986993
$user_capabilities = get_user_meta( $user->ID, 'wp_capabilities', true );
987994

988995
// Loop through each capability and only return the non-inherited ones
@@ -993,7 +1000,9 @@ public function list_caps( $args, $assoc_args ) {
9931000
}
9941001
break;
9951002
case 'role':
996-
// Get the user's capabilities
1003+
/**
1004+
* @var array<string, int> $user_capabilities
1005+
*/
9971006
$user_capabilities = get_user_meta( $user->ID, 'wp_capabilities', true );
9981007

9991008
// Loop through each capability and only return the inherited ones (including the role name)
@@ -1092,6 +1101,10 @@ public function import_csv( $args, $assoc_args ) {
10921101
$file_object->setFlags( SplFileObject::READ_CSV );
10931102
$csv_data = [];
10941103
$indexes = [];
1104+
1105+
/**
1106+
* @var string[] $line
1107+
*/
10951108
foreach ( $file_object as $line ) {
10961109
if ( empty( $line[0] ) ) {
10971110
continue;
@@ -1102,6 +1115,9 @@ public function import_csv( $args, $assoc_args ) {
11021115
continue;
11031116
}
11041117

1118+
/**
1119+
* @var array<string, string> $data
1120+
*/
11051121
$data = [];
11061122

11071123
foreach ( $indexes as $n => $key ) {
@@ -1114,6 +1130,9 @@ public function import_csv( $args, $assoc_args ) {
11141130
$csv_data = new CsvIterator( $filename );
11151131
}
11161132

1133+
/**
1134+
* @var array{ID: string, role: string, roles: string, user_pass: string, user_registered: string, display_name: string|false, user_login: string, user_email: string} $new_user
1135+
*/
11171136
foreach ( $csv_data as $new_user ) {
11181137
$defaults = [
11191138
'role' => get_option( 'default_role' ),
@@ -1281,7 +1300,7 @@ public function import_csv( $args, $assoc_args ) {
12811300
*/
12821301
public function reset_password( $args, $assoc_args ) {
12831302
$porcelain = Utils\get_flag_value( $assoc_args, 'porcelain' );
1284-
$skip_email = Utils\get_flag_value( $assoc_args, 'skip-email' );
1303+
$skip_email = (bool) Utils\get_flag_value( $assoc_args, 'skip-email' );
12851304
$show_new_pass = Utils\get_flag_value( $assoc_args, 'show-password' );
12861305

12871306
if ( $skip_email ) {

src/User_Session_Command.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct() {
7272
public function destroy( $args, $assoc_args ) {
7373
$user = $this->fetcher->get_check( $args[0] );
7474
$token = $args[1] ?? null;
75-
$all = Utils\get_flag_value( $assoc_args, 'all', false );
75+
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
7676
$manager = WP_Session_Tokens::get_instance( $user->ID );
7777

7878
if ( $token && $all ) {
@@ -174,6 +174,10 @@ protected function get_all_sessions( WP_Session_Tokens $manager ) {
174174
// Make the private session data accessible to WP-CLI
175175
$get_sessions = new ReflectionMethod( $manager, 'get_sessions' );
176176
$get_sessions->setAccessible( true );
177+
178+
/**
179+
* @var array<array{token: string|int, login_time: string, login: int, expiration_time: string, expiration: int}> $sessions
180+
*/
177181
$sessions = $get_sessions->invoke( $manager );
178182

179183
array_walk(

src/WP_CLI/CommandWithMeta.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function list_( $args, $assoc_args ) {
9191
foreach ( $values as $item_value ) {
9292

9393
if ( Utils\get_flag_value( $assoc_args, 'unserialize' ) ) {
94-
$item_value = maybe_unserialize( $item_value );
94+
$item_value = maybe_unserialize( (string) $item_value );
9595
}
9696

9797
$items[] = (object) [
@@ -159,7 +159,7 @@ public function get( $args, $assoc_args ) {
159159
list( $object_id, $meta_key ) = $args;
160160

161161
$object_id = $this->check_object_id( $object_id );
162-
$single = Utils\get_flag_value( $assoc_args, 'single', true );
162+
$single = (bool) Utils\get_flag_value( $assoc_args, 'single', true );
163163

164164
$value = $this->get_metadata( $object_id, $meta_key, $single );
165165

@@ -504,6 +504,8 @@ protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_va
504504
* specified.
505505
*
506506
* @return mixed Single metadata value, or array of values.
507+
*
508+
* @phpstan-return ($single is true ? string : array<string>)
507509
*/
508510
protected function get_metadata( $object_id, $meta_key = '', $single = false ) {
509511
return get_metadata( $this->meta_type, $object_id, $meta_key, $single );

src/WP_CLI/CommandWithTerms.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,15 @@ public function remove( $args, $assoc_args ) {
148148

149149
$this->taxonomy_exists( $taxonomy );
150150

151+
/**
152+
* @var string|null $field
153+
*/
151154
$field = Utils\get_flag_value( $assoc_args, 'by' );
152155
if ( $field ) {
153156
$terms = $this->prepare_terms( $field, $terms, $taxonomy );
154157
}
155158

156-
if ( Utils\get_flag_value( $assoc_args, 'all' ) ) {
159+
if ( (bool) Utils\get_flag_value( $assoc_args, 'all' ) ) {
157160

158161
// No need to specify terms while removing all terms.
159162
if ( $terms ) {
@@ -167,7 +170,12 @@ public function remove( $args, $assoc_args ) {
167170
if ( 'category' === $taxonomy ) {
168171

169172
// Set default category to post.
170-
$default_category = (int) get_option( 'default_category' );
173+
174+
/**
175+
* @var string $default_category
176+
*/
177+
$default_category = get_option( 'default_category' );
178+
$default_category = (int) $default_category;
171179
$default_category = ( ! empty( $default_category ) ) ? $default_category : 1;
172180
$default_category = wp_set_object_terms( $object_id, [ $default_category ], $taxonomy, true );
173181

@@ -238,6 +246,9 @@ public function add( $args, $assoc_args ) {
238246

239247
$this->taxonomy_exists( $taxonomy );
240248

249+
/**
250+
* @var string|null $field
251+
*/
241252
$field = Utils\get_flag_value( $assoc_args, 'by' );
242253
if ( $field ) {
243254
$terms = $this->prepare_terms( $field, $terms, $taxonomy );
@@ -286,6 +297,9 @@ public function set( $args, $assoc_args ) {
286297

287298
$this->taxonomy_exists( $taxonomy );
288299

300+
/**
301+
* @var string|null $field
302+
*/
289303
$field = Utils\get_flag_value( $assoc_args, 'by' );
290304
if ( $field ) {
291305
$terms = $this->prepare_terms( $field, $terms, $taxonomy );

0 commit comments

Comments
 (0)