Skip to content

Commit b0fafd7

Browse files
committed
More fixes
1 parent a8053d6 commit b0fafd7

File tree

10 files changed

+83
-54
lines changed

10 files changed

+83
-54
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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/Plugin_AutoUpdates_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public function __construct() {
7777
* @param array{all?: bool, 'disabled-only'?: bool} $assoc_args Associative arguments.
7878
*/
7979
public function enable( $args, $assoc_args ) {
80-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
81-
$disabled_only = (bool) Utils\get_flag_value( $assoc_args, 'disabled-only', false );
80+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
81+
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );
8282

8383
$args = $this->check_optional_args_and_all( $args, $all );
8484
if ( ! $args ) {
@@ -154,7 +154,7 @@ public function enable( $args, $assoc_args ) {
154154
* Success: Disabled 1 of 1 plugin auto-updates.
155155
*/
156156
public function disable( $args, $assoc_args ) {
157-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
157+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
158158
$enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false );
159159

160160
$args = $this->check_optional_args_and_all( $args, $all );
@@ -262,7 +262,7 @@ public function disable( $args, $assoc_args ) {
262262
* duplicate-post
263263
*/
264264
public function status( $args, $assoc_args ) {
265-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
265+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
266266
$enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false );
267267
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );
268268

src/Plugin_Command.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use WP_CLI\CommandWithUpgrade;
34
use WP_CLI\ParsePluginNameInput;
45
use WP_CLI\Utils;
56
use WP_CLI\WpOrgApi;
@@ -43,9 +44,9 @@
4344
* @package wp-cli
4445
*
4546
* @phpstan-type PluginInformation object{name: string, slug: non-empty-string, version: string, new_version: string, download_link: string, requires_php?: string, requires?: string, package: string}&\stdClass
47+
* @extends CommandWithUpgrade<string,>
4648
*/
47-
class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
48-
49+
class Plugin_Command extends CommandWithUpgrade {
4950
use ParsePluginNameInput;
5051

5152
protected $item_type = 'plugin';
@@ -72,6 +73,8 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
7273
* Plugin fetcher instance.
7374
*
7475
* @var \WP_CLI\Fetchers\Plugin
76+
*
77+
* @phpstan-ignore property.phpDocType (To be fixed with in https://github.com/wp-cli/wp-cli/pull/6096)
7578
*/
7679
protected $fetcher;
7780

@@ -354,9 +357,9 @@ protected function get_all_items() {
354357
* @param array $args
355358
* @param array $assoc_args
356359
*/
357-
public function activate( $args, $assoc_args = array() ) {
358-
$network_wide = (bool) Utils\get_flag_value( $assoc_args, 'network', false );
359-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
360+
public function activate( $args, $assoc_args = [] ) {
361+
$network_wide = Utils\get_flag_value( $assoc_args, 'network', false );
362+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
360363
$all_exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' );
361364

362365
/**
@@ -453,9 +456,9 @@ public function activate( $args, $assoc_args = array() ) {
453456
* Plugin 'ninja-forms' deactivated.
454457
* Success: Deactivated 2 of 2 plugins.
455458
*/
456-
public function deactivate( $args, $assoc_args = array() ) {
457-
$network_wide = (bool) Utils\get_flag_value( $assoc_args, 'network' );
458-
$disable_all = (bool) Utils\get_flag_value( $assoc_args, 'all' );
459+
public function deactivate( $args, $assoc_args = [] ) {
460+
$network_wide = Utils\get_flag_value( $assoc_args, 'network' );
461+
$disable_all = Utils\get_flag_value( $assoc_args, 'all' );
459462
$disable_all_exclude = Utils\get_flag_value( $assoc_args, 'exclude', '' );
460463

461464
/**
@@ -550,7 +553,7 @@ public function deactivate( $args, $assoc_args = array() ) {
550553
* Plugin 'akismet' activated.
551554
* Success: Toggled 1 of 1 plugins.
552555
*/
553-
public function toggle( $args, $assoc_args = array() ) {
556+
public function toggle( $args, $assoc_args ) {
554557
$network_wide = Utils\get_flag_value( $assoc_args, 'network' );
555558

556559
$successes = 0;
@@ -752,7 +755,7 @@ protected function install_from_repo( $slug, $assoc_args ) {
752755
* @alias upgrade
753756
*/
754757
public function update( $args, $assoc_args ) {
755-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
758+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
756759

757760
$args = $this->check_optional_args_and_all( $args, $all );
758761
if ( ! $args ) {
@@ -792,10 +795,11 @@ protected function get_item_list() {
792795

793796
foreach ( $this->get_all_plugins() as $file => $details ) {
794797
$all_update_info = $this->get_update_info();
795-
$update_info = ( isset( $all_update_info->response[ $file ] ) && null !== $all_update_info->response[ $file ] ) ? (array) $all_update_info->response[ $file ] : null;
796-
$name = Utils\get_plugin_name( $file );
797-
$wporg_info = $this->get_wporg_data( $name );
798-
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $file, false, false );
798+
// @phpstan-ignore notIdentical.alwaysTrue
799+
$update_info = ( isset( $all_update_info->response[ $file ] ) && null !== $all_update_info->response[ $file ] ) ? (array) $all_update_info->response[ $file ] : null;
800+
$name = Utils\get_plugin_name( $file );
801+
$wporg_info = $this->get_wporg_data( $name );
802+
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $file, false, false );
799803

800804
if ( ! isset( $duplicate_names[ $name ] ) ) {
801805
$duplicate_names[ $name ] = array();
@@ -1207,8 +1211,8 @@ public function get( $args, $assoc_args ) {
12071211
* Uninstalled and deleted 'tinymce-templates' plugin.
12081212
* Success: Uninstalled 2 of 2 plugins.
12091213
*/
1210-
public function uninstall( $args, $assoc_args = array() ) {
1211-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
1214+
public function uninstall( $args, $assoc_args = [] ) {
1215+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
12121216
$all_exclude = Utils\get_flag_value( $assoc_args, 'exclude', false );
12131217

12141218
/**
@@ -1340,7 +1344,7 @@ public function uninstall( $args, $assoc_args = array() ) {
13401344
*
13411345
* @subcommand is-installed
13421346
*/
1343-
public function is_installed( $args, $assoc_args = array() ) {
1347+
public function is_installed( $args, $assoc_args ) {
13441348
if ( $this->fetcher->get( $args[0] ) ) {
13451349
WP_CLI::halt( 0 );
13461350
} else {
@@ -1370,8 +1374,8 @@ public function is_installed( $args, $assoc_args = array() ) {
13701374
*
13711375
* @subcommand is-active
13721376
*/
1373-
public function is_active( $args, $assoc_args = array() ) {
1374-
$network_wide = (bool) Utils\get_flag_value( $assoc_args, 'network' );
1377+
public function is_active( $args, $assoc_args ) {
1378+
$network_wide = Utils\get_flag_value( $assoc_args, 'network' );
13751379

13761380
$plugin = $this->fetcher->get( $args[0] );
13771381

@@ -1414,8 +1418,8 @@ public function is_active( $args, $assoc_args = array() ) {
14141418
* Deleted 'tinymce-templates' plugin.
14151419
* Success: Deleted 2 of 2 plugins.
14161420
*/
1417-
public function delete( $args, $assoc_args = array() ) {
1418-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
1421+
public function delete( $args, $assoc_args ) {
1422+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
14191423
$all_exclude = Utils\get_flag_value( $assoc_args, 'exclude', false );
14201424

14211425
/**

src/Theme_AutoUpdates_Command.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
*/
2929
class Theme_AutoUpdates_Command {
3030

31+
/**
32+
* @use ParseThemeNameInput<\WP_Theme>
33+
*/
3134
use ParseThemeNameInput;
3235

3336
/**
@@ -74,7 +77,7 @@ public function __construct() {
7477
* Success: Enabled 1 of 1 theme auto-updates.
7578
*/
7679
public function enable( $args, $assoc_args ) {
77-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
80+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
7881
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );
7982

8083
$args = $this->check_optional_args_and_all( $args, $all );
@@ -151,8 +154,8 @@ public function enable( $args, $assoc_args ) {
151154
* Success: Disabled 1 of 1 theme auto-updates.
152155
*/
153156
public function disable( $args, $assoc_args ) {
154-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
155-
$enabled_only = (bool) Utils\get_flag_value( $assoc_args, 'enabled-only', false );
157+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
158+
$enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false );
156159

157160
$args = $this->check_optional_args_and_all( $args, $all );
158161
if ( ! $args ) {
@@ -259,9 +262,9 @@ public function disable( $args, $assoc_args ) {
259262
* twentyseventeen
260263
*/
261264
public function status( $args, $assoc_args ) {
262-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
263-
$enabled_only = (bool) Utils\get_flag_value( $assoc_args, 'enabled-only', false );
264-
$disabled_only = (bool) Utils\get_flag_value( $assoc_args, 'disabled-only', false );
265+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
266+
$enabled_only = Utils\get_flag_value( $assoc_args, 'enabled-only', false );
267+
$disabled_only = Utils\get_flag_value( $assoc_args, 'disabled-only', false );
265268

266269
if ( $enabled_only && $disabled_only ) {
267270
WP_CLI::error(

src/Theme_Command.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@
4343
* @package wp-cli
4444
*
4545
* @phpstan-type ThemeInformation object{name: string, slug: non-empty-string, version: string, new_version: string, download_link: string, requires_php?: string, requires?: string}&\stdClass
46+
* @extends CommandWithUpgrade<\WP_Theme>
4647
*/
4748
class Theme_Command extends CommandWithUpgrade {
4849

50+
/**
51+
* @use ParseThemeNameInput<\WP_Theme>
52+
*/
4953
use ParseThemeNameInput;
5054

5155
protected $item_type = 'theme';
@@ -214,8 +218,8 @@ protected function get_all_items() {
214218
* $ wp theme activate twentysixteen
215219
* Success: Switched to 'Twenty Sixteen' theme.
216220
*
217-
* @param array $args
218-
* @param array $assoc_args
221+
* @param string[] $args Positional arguments.
222+
* @param array $assoc_args Associative arguments. Unused.
219223
*/
220224
public function activate( $args, $assoc_args = [] ) {
221225
$theme = $this->fetcher->get_check( $args[0] );
@@ -713,7 +717,7 @@ public function get( $args, $assoc_args ) {
713717
* @alias upgrade
714718
*/
715719
public function update( $args, $assoc_args ) {
716-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
720+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
717721

718722
$args = $this->check_optional_args_and_all( $args, $all );
719723
if ( ! $args ) {
@@ -753,7 +757,7 @@ public function update( $args, $assoc_args ) {
753757
*
754758
* @subcommand is-installed
755759
*/
756-
public function is_installed( $args, $assoc_args = array() ) {
760+
public function is_installed( $args, $assoc_args ) {
757761
$theme = wp_get_theme( $args[0] );
758762

759763
if ( $theme->exists() ) {
@@ -782,7 +786,7 @@ public function is_installed( $args, $assoc_args = array() ) {
782786
*
783787
* @subcommand is-active
784788
*/
785-
public function is_active( $args, $assoc_args = array() ) {
789+
public function is_active( $args, $assoc_args ) {
786790
$theme = wp_get_theme( $args[0] );
787791

788792
if ( ! $theme->exists() ) {
@@ -818,7 +822,7 @@ public function is_active( $args, $assoc_args = array() ) {
818822
*/
819823
public function delete( $args, $assoc_args ) {
820824

821-
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
825+
$all = Utils\get_flag_value( $assoc_args, 'all', false );
822826

823827
$args = $this->check_optional_args_and_all( $args, $all, 'delete' );
824828
if ( ! $args ) {

src/Theme_Mod_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function list_( $args, $assoc_args ) {
204204
* @param string[] $args Positional arguments.
205205
* @param array{all?: bool} $assoc_args Associative arguments.
206206
*/
207-
public function remove( $args, $assoc_args, ) {
207+
public function remove( $args, $assoc_args ) {
208208

209209
if ( ! \WP_CLI\Utils\get_flag_value( $assoc_args, 'all' ) && empty( $args ) ) {
210210
WP_CLI::error( 'You must specify at least one mod or use --all.' );

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
/**
1515
* @phpstan-import-type ThemeInformation from \Theme_Command
1616
* @phpstan-import-type PluginInformation from \Plugin_Command
17+
*
18+
* @template T
1719
*/
1820
abstract class CommandWithUpgrade extends \WP_CLI_Command {
1921

@@ -78,12 +80,25 @@ abstract protected function filter_item_list( $items, $args );
7880

7981
abstract protected function get_all_items();
8082

83+
/**
84+
* Get the status for a given extension.
85+
*
86+
* @param T $file Extension to get the status for.
87+
*
88+
* @return string Status of the extension.
89+
*/
8190
abstract protected function get_status( $file );
8291

8392
abstract protected function status_single( $args );
8493

8594
abstract protected function install_from_repo( $slug, $assoc_args );
8695

96+
/**
97+
* Activates an extension.
98+
*
99+
* @param string[] $args Positional arguments.
100+
* @param array $assoc_args Associative arguments.
101+
*/
87102
abstract public function activate( $args, $assoc_args = [] );
88103

89104
public function status( $args ) {
@@ -357,8 +372,8 @@ protected static function alter_api_response( $response, $version ) {
357372
}
358373

359374
protected function get_upgrader( $assoc_args ) {
360-
$force = (bool) Utils\get_flag_value( $assoc_args, 'force', false );
361-
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
375+
$force = Utils\get_flag_value( $assoc_args, 'force', false );
376+
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
362377
$upgrader_class = $this->get_upgrader_class( $force );
363378
return Utils\get_upgrader( $upgrader_class, $insecure );
364379
}
@@ -395,15 +410,15 @@ function ( $item ) {
395410
}
396411
);
397412

398-
$minor = (bool) Utils\get_flag_value( $assoc_args, 'minor', false );
399-
$patch = (bool) Utils\get_flag_value( $assoc_args, 'patch', false );
413+
$minor = Utils\get_flag_value( $assoc_args, 'minor', false );
414+
$patch = Utils\get_flag_value( $assoc_args, 'patch', false );
400415

401416
if (
402417
in_array( $this->item_type, [ 'plugin', 'theme' ], true ) &&
403418
( $minor || $patch )
404419
) {
405420
$type = $minor ? 'minor' : 'patch';
406-
$insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false );
421+
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
407422

408423
$items_to_update = self::get_minor_or_patch_updates( $items_to_update, $type, $insecure, true, $this->item_type );
409424
}
@@ -566,14 +581,14 @@ static function ( $result ) {
566581
protected function _list( $_, $assoc_args ) {
567582

568583
// Force WordPress to check for updates if `--skip-update-check` is not passed.
569-
if ( false === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {
584+
if ( false === Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) {
570585
delete_site_transient( $this->upgrade_transient );
571586
call_user_func( $this->upgrade_refresh );
572587
}
573588

574589
$all_items = $this->get_all_items();
575590

576-
if ( false !== (bool) Utils\get_flag_value( $assoc_args, 'recently-active', false ) ) {
591+
if ( false !== Utils\get_flag_value( $assoc_args, 'recently-active', false ) ) {
577592
$all_items = array_filter(
578593
$all_items,
579594
function ( $value ) {
@@ -656,11 +671,11 @@ protected function has_update( $slug ) {
656671
/**
657672
* Get the available update info
658673
*
659-
* @return object{checked: array<string, string>, response: array<string, string>, no_update: array<string, object{new_version: string, package: string, requires: string}&\stdClass>} $update_list
674+
* @return object{checked: array<string, string>, response: array<string, array<string, string|null>>, no_update: array<string, object{new_version: string, package: string, requires: string}&\stdClass>} $update_list
660675
*/
661676
protected function get_update_info() {
662677
/**
663-
* @var object{checked: array<string, string>, response: array<string, string>, no_update: array<string, object{new_version: string, package: string, requires: string}&\stdClass>} $update_list
678+
* @var object{checked: array<string, string>, response: array<string, array<string, string|null>>, no_update: array<string, object{new_version: string, package: string, requires: string}&\stdClass>} $update_list
664679
*/
665680
$update_list = get_site_transient( $this->upgrade_transient );
666681

src/WP_CLI/Fetchers/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Plugin extends Base {
1717
*
1818
* @param string $name Plugin name.
1919
* @return object{name: string, file: string}|false
20+
*
21+
* @phpstan-ignore method.childParameterType (To be fixed with in https://github.com/wp-cli/wp-cli/pull/6096)
2022
*/
2123
public function get( $name ) {
2224
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling native WordPress hook.

src/WP_CLI/Fetchers/Theme.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Theme extends Base {
1919
*
2020
* @param string $name
2121
* @return object|false
22+
*
23+
* @phpstan-ignore method.childParameterType (To be fixed with in https://github.com/wp-cli/wp-cli/pull/6096)
2224
*/
2325
public function get( $name ) {
2426
// Workaround to equalize folder naming conventions across Win/Mac/Linux.

0 commit comments

Comments
 (0)