Skip to content

Commit d8d7d12

Browse files
authored
Merge pull request #166 from wp-cli/add/phpstan
2 parents 574a1ef + 91e0724 commit d8d7d12

File tree

7 files changed

+161
-29
lines changed

7 files changed

+161
-29
lines changed

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
"wp-cli/db-command": "^1.3 || ^2",
1919
"wp-cli/entity-command": "^1.3 || ^2",
2020
"wp-cli/extension-command": "^1.2 || ^2",
21-
"wp-cli/wp-cli-tests": "^4"
21+
"wp-cli/wp-cli-tests": "^5"
2222
},
2323
"config": {
2424
"process-timeout": 7200,
2525
"sort-packages": true,
2626
"allow-plugins": {
2727
"dealerdirect/phpcodesniffer-composer-installer": true,
28-
"johnpbloch/wordpress-core-installer": true
28+
"johnpbloch/wordpress-core-installer": true,
29+
"phpstan/extension-installer": true
2930
},
3031
"lock": false
3132
},
@@ -73,12 +74,14 @@
7374
"behat-rerun": "rerun-behat-tests",
7475
"lint": "run-linter-tests",
7576
"phpcs": "run-phpcs-tests",
77+
"phpstan": "run-phpstan-tests",
7678
"phpcbf": "run-phpcbf-cleanup",
7779
"phpunit": "run-php-unit-tests",
7880
"prepare-tests": "install-package-tests",
7981
"test": [
8082
"@lint",
8183
"@phpcs",
84+
"@phpstan",
8285
"@phpunit",
8386
"@behat"
8487
]

phpstan.neon.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- src
5+
- language-command.php
6+
scanDirectories:
7+
- vendor/wp-cli/wp-cli/php
8+
scanFiles:
9+
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
10+
treatPhpDocTypesAsCertain: false
11+
strictRules:
12+
uselessCast: true
13+
closureUsesThis: true
14+
overwriteVariablesWithLoop: true
15+
matchingInheritedMethodNames: true
16+
numericOperandsInArithmeticOperators: true
17+
switchConditionsMatchingType: true
18+
ignoreErrors:
19+
- identifier: missingType.iterableValue
20+
- identifier: missingType.property
21+
- identifier: missingType.parameter
22+
- identifier: missingType.return

src/Core_Language_Command.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Core_Language_Command extends WP_CLI\CommandWithTranslation {
9393
* | az | Azerbaijani | uninstalled |
9494
*
9595
* @subcommand list
96+
*
97+
* @param string[] $args Positional arguments. Unused.
98+
* @param array{field?: string, format: string, language?: string, english_name?: string, native_name?: string, status?: string, update?: string, updated?: string} $assoc_args Associative arguments.
9699
*/
97100
public function list_( $args, $assoc_args ) {
98101
$translations = $this->get_all_languages();
@@ -154,8 +157,10 @@ function ( $translation ) use ( $available, $current_locale, $updates ) {
154157
* 1
155158
*
156159
* @subcommand is-installed
160+
*
161+
* @param array{string} $args Positional arguments.
157162
*/
158-
public function is_installed( $args, $assoc_args = array() ) {
163+
public function is_installed( $args ) {
159164
list( $language_code ) = $args;
160165
$available = $this->get_installed_languages();
161166
if ( in_array( $language_code, $available, true ) ) {
@@ -191,6 +196,9 @@ public function is_installed( $args, $assoc_args = array() ) {
191196
* Success: Installed 1 of 1 languages.
192197
*
193198
* @subcommand install
199+
*
200+
* @param string[] $args Positional arguments.
201+
* @param array{activate?: bool} $assoc_args Associative arguments.
194202
*/
195203
public function install( $args, $assoc_args ) {
196204
$language_codes = (array) $args;
@@ -253,8 +261,10 @@ public function install( $args, $assoc_args ) {
253261
*
254262
* @subcommand uninstall
255263
* @throws WP_CLI\ExitException
264+
*
265+
* @param string[] $args Positional arguments.
256266
*/
257-
public function uninstall( $args, $assoc_args ) {
267+
public function uninstall( $args ) {
258268
global $wp_filesystem;
259269

260270
$dir = 'core' === $this->obj_type ? '' : "/$this->obj_type";
@@ -339,6 +349,9 @@ public function uninstall( $args, $assoc_args ) {
339349
* Success: Updated 1/1 translation.
340350
*
341351
* @subcommand update
352+
*
353+
* @param string[] $args Positional arguments.
354+
* @param array{'dry-run'?: bool} $assoc_args Associative arguments.
342355
*/
343356
public function update( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found -- Overruling the documentation, so not useless ;-).
344357
parent::update( $args, $assoc_args );
@@ -362,8 +375,10 @@ public function update( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnaly
362375
*
363376
* @subcommand activate
364377
* @throws WP_CLI\ExitException
378+
*
379+
* @param array{string} $args Positional arguments.
365380
*/
366-
public function activate( $args, $assoc_args ) {
381+
public function activate( $args ) {
367382
\WP_CLI::warning( 'This command is deprecated. use wp site switch-language instead' );
368383

369384
list( $language_code ) = $args;

src/Plugin_Language_Command.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class Plugin_Language_Command extends WP_CLI\CommandWithTranslation {
103103
* | az | Azerbaijani | uninstalled |
104104
*
105105
* @subcommand list
106+
*
107+
* @param string[] $args Positional arguments.
108+
* @param array{all?: bool, field?: string, format: string, plugin?: string, language?: string, english_name?: string, native_name?: string, status?: string, update?: string, updated?: string} $assoc_args Associative arguments.
106109
*/
107110
public function list_( $args, $assoc_args ) {
108111
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );
@@ -154,7 +157,7 @@ public function list_( $args, $assoc_args ) {
154157

155158
// Support features like --status=active.
156159
foreach ( array_keys( $translation ) as $field ) {
157-
if ( isset( $assoc_args[ $field ] ) && ! in_array( $translation[ $field ], array_map( 'trim', explode( ',', $assoc_args[ $field ] ) ), true ) ) {
160+
if ( isset( $assoc_args[ $field ] ) && ! in_array( $translation[ $field ], array_map( 'trim', explode( ',', (string) $assoc_args[ $field ] ) ), true ) ) {
158161
continue 2;
159162
}
160163
}
@@ -188,10 +191,12 @@ public function list_( $args, $assoc_args ) {
188191
* 1
189192
*
190193
* @subcommand is-installed
194+
*
195+
* @param non-empty-array<string> $args Positional arguments.
191196
*/
192-
public function is_installed( $args, $assoc_args = array() ) {
197+
public function is_installed( $args ) {
193198
$plugin = array_shift( $args );
194-
$language_codes = (array) $args;
199+
$language_codes = $args;
195200

196201
$available = $this->get_installed_languages( $plugin );
197202

@@ -244,6 +249,9 @@ public function is_installed( $args, $assoc_args = array() ) {
244249
* Success: Installed 1 of 1 languages.
245250
*
246251
* @subcommand install
252+
*
253+
* @param string[] $args Positional arguments.
254+
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
247255
*/
248256
public function install( $args, $assoc_args ) {
249257
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );
@@ -267,7 +275,7 @@ public function install( $args, $assoc_args ) {
267275
*/
268276
private function install_one( $args, $assoc_args ) {
269277
$plugin = array_shift( $args );
270-
$language_codes = (array) $args;
278+
$language_codes = $args;
271279
$count = count( $language_codes );
272280

273281
$available = $this->get_installed_languages( $plugin );
@@ -419,6 +427,9 @@ private function install_many( $args, $assoc_args ) {
419427
* Success: Uninstalled 1 of 1 languages.
420428
*
421429
* @subcommand uninstall
430+
*
431+
* @param string[] $args Positional arguments.
432+
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
422433
*/
423434
public function uninstall( $args, $assoc_args ) {
424435
/** @var WP_Filesystem_Base $wp_filesystem */
@@ -471,6 +482,9 @@ public function uninstall( $args, $assoc_args ) {
471482
$errors = 0;
472483
$skips = 0;
473484

485+
/**
486+
* @var string $plugin
487+
*/
474488
foreach ( $plugins as $plugin ) {
475489
$available = $this->get_installed_languages( $plugin );
476490

@@ -584,6 +598,9 @@ public function uninstall( $args, $assoc_args ) {
584598
* Success: Updated 1/1 translation.
585599
*
586600
* @subcommand update
601+
*
602+
* @param string[] $args Positional arguments.
603+
* @param array{'dry-run'?: bool, all?: bool} $assoc_args Associative arguments.
587604
*/
588605
public function update( $args, $assoc_args ) {
589606
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );

src/Theme_Language_Command.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class Theme_Language_Command extends WP_CLI\CommandWithTranslation {
103103
* | az | Azerbaijani | uninstalled |
104104
*
105105
* @subcommand list
106+
*
107+
* @param string[] $args Positional arguments.
108+
* @param array{all?: bool, field?: string, format: string, theme?: string, language?: string, english_name?: string, native_name?: string, status?: string, update?: string, updated?: string} $assoc_args Associative arguments.
106109
*/
107110
public function list_( $args, $assoc_args ) {
108111
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );
@@ -194,8 +197,10 @@ function ( $file ) {
194197
* 1
195198
*
196199
* @subcommand is-installed
200+
*
201+
* @param non-empty-array<string> $args Positional arguments.
197202
*/
198-
public function is_installed( $args, $assoc_args = array() ) {
203+
public function is_installed( $args ) {
199204
$theme = array_shift( $args );
200205
$language_codes = (array) $args;
201206

@@ -249,6 +254,9 @@ public function is_installed( $args, $assoc_args = array() ) {
249254
* Success: Installed 1 of 1 languages.
250255
*
251256
* @subcommand install
257+
*
258+
* @param string[] $args Positional arguments.
259+
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
252260
*/
253261
public function install( $args, $assoc_args ) {
254262
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );
@@ -272,7 +280,7 @@ public function install( $args, $assoc_args ) {
272280
*/
273281
private function install_one( $args, $assoc_args ) {
274282
$theme = array_shift( $args );
275-
$language_codes = (array) $args;
283+
$language_codes = $args;
276284
$count = count( $language_codes );
277285

278286
$available = $this->get_installed_languages( $theme );
@@ -315,7 +323,11 @@ private function install_one( $args, $assoc_args ) {
315323
*/
316324
private function install_many( $args, $assoc_args ) {
317325
$language_codes = (array) $args;
318-
$themes = wp_get_themes();
326+
327+
/**
328+
* @var \WP_Theme[] $themes
329+
*/
330+
$themes = wp_get_themes();
319331

320332
if ( empty( $assoc_args['format'] ) ) {
321333
$assoc_args['format'] = 'table';
@@ -343,22 +355,27 @@ private function install_many( $args, $assoc_args ) {
343355

344356
$available = $this->get_installed_languages( $theme_name );
345357

358+
/**
359+
* @var string $display_name
360+
*/
361+
$display_name = $theme_details['Name'];
362+
346363
foreach ( $language_codes as $language_code ) {
347364
$result = [
348365
'name' => $theme_name,
349366
'locale' => $language_code,
350367
];
351368

352369
if ( in_array( $language_code, $available, true ) ) {
353-
\WP_CLI::log( "Language '{$language_code}' for '{$theme_details['Name']}' already installed." );
370+
\WP_CLI::log( "Language '{$language_code}' for '{$display_name}' already installed." );
354371
$result['status'] = 'already installed';
355372
++$skips;
356373
} else {
357374
$response = $this->download_language_pack( $language_code, $theme_name );
358375

359376
if ( is_wp_error( $response ) ) {
360377
\WP_CLI::warning( $response );
361-
\WP_CLI::log( "Language '{$language_code}' for '{$theme_details['Name']}' not installed." );
378+
\WP_CLI::log( "Language '{$language_code}' for '{$display_name}' not installed." );
362379

363380
if ( 'not_found' === $response->get_error_code() ) {
364381
$result['status'] = 'not available';
@@ -368,7 +385,7 @@ private function install_many( $args, $assoc_args ) {
368385
++$errors;
369386
}
370387
} else {
371-
\WP_CLI::log( "Language '{$language_code}' for '{$theme_details['Name']}' installed." );
388+
\WP_CLI::log( "Language '{$language_code}' for '{$display_name}' installed." );
372389
$result['status'] = 'installed';
373390
++$successes;
374391
}
@@ -423,6 +440,9 @@ private function install_many( $args, $assoc_args ) {
423440
* Success: Uninstalled 1 of 1 languages.
424441
*
425442
* @subcommand uninstall
443+
*
444+
* @param string[] $args Positional arguments.
445+
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
426446
*/
427447
public function uninstall( $args, $assoc_args ) {
428448
/** @var WP_Filesystem_Base $wp_filesystem */
@@ -481,6 +501,9 @@ public function uninstall( $args, $assoc_args ) {
481501
// As of WP 4.0, no API for deleting a language pack
482502
WP_Filesystem();
483503

504+
/**
505+
* @var string $theme
506+
*/
484507
foreach ( $process_themes as $theme ) {
485508
$available_languages = $this->get_installed_languages( $theme );
486509

@@ -594,6 +617,9 @@ public function uninstall( $args, $assoc_args ) {
594617
* Success: Updated 1/1 translation.
595618
*
596619
* @subcommand update
620+
*
621+
* @param string[] $args Positional arguments.
622+
* @param array{'dry-run'?: bool, all?: bool} $assoc_args Associative arguments.
597623
*/
598624
public function update( $args, $assoc_args ) {
599625
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );

0 commit comments

Comments
 (0)