Skip to content

Commit 0187f2b

Browse files
authored
Merge pull request #6019 from wp-cli/try/phpstan
Code quality improvements powered by PHPStan
2 parents 349cf0c + 85f9a59 commit 0187f2b

19 files changed

+217
-119
lines changed

php/WP_CLI/Configurator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public function get_aliases() {
148148
/**
149149
* Splits a list of arguments into positional, associative and config.
150150
*
151-
* @param array(string) $arguments
152-
* @return array(array)
151+
* @param array<string> $arguments
152+
* @return array<array<string>>
153153
*/
154154
public function parse_args( $arguments ) {
155155
list( $positional_args, $mixed_args, $global_assoc, $local_assoc ) = self::extract_assoc( $arguments );
@@ -160,8 +160,8 @@ public function parse_args( $arguments ) {
160160
/**
161161
* Splits positional args from associative args.
162162
*
163-
* @param array $arguments
164-
* @return array(array)
163+
* @param array<string> $arguments
164+
* @return array{0: array<string>, 1: array<array{0: string, 1: string|bool}>, 2: array<array{0: string, 1: string|bool}>, 3: array<array{0: string, 1: string|bool}>}
165165
*/
166166
public static function extract_assoc( $arguments ) {
167167
$positional_args = [];

php/WP_CLI/Dispatcher/CommandFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class CommandFactory {
2323
/**
2424
* Create a new CompositeCommand (or Subcommand if class has __invoke())
2525
*
26-
* @param string $name Represents how the command should be invoked
27-
* @param string $callable A subclass of WP_CLI_Command, a function, or a closure
26+
* @param string $name Represents how the command should be invoked
27+
* @param string|callable-string|callable|array $callable A subclass of WP_CLI_Command, a function, or a closure
2828
* @param mixed $parent The new command's parent Composite (or Root) command
2929
*/
3030
public static function create( $name, $callable, $parent ) {

php/WP_CLI/Dispatcher/CompositeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private static function get_aliases( $subcommands ) {
277277
/**
278278
* Composite commands can only be known by one name.
279279
*
280-
* @return false
280+
* @return string|false
281281
*/
282282
public function get_alias() {
283283
return false;

php/WP_CLI/Exception/NonExistentKeyException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WP_CLI\Exception;
44

55
use OutOfBoundsException;
6+
use WP_CLI\Traverser\RecursiveDataStructureTraverser;
67

78
class NonExistentKeyException extends OutOfBoundsException {
89
/** @var RecursiveDataStructureTraverser */

php/WP_CLI/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static function zip_error_msg( $error_code ) {
280280
/**
281281
* Return formatted error message from ProcessRun of tar command.
282282
*
283-
* @param Processrun $process_run
283+
* @param ProcessRun $process_run
284284
* @return string|int The error message of the process, if available;
285285
* otherwise the return code.
286286
*/

php/WP_CLI/Fetchers/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class Base {
1818
protected $msg;
1919

2020
/**
21-
* @param string $arg The raw CLI argument.
21+
* @param string|int $arg The raw CLI argument.
2222
* @return mixed|false The item if found; false otherwise.
2323
*/
2424
abstract public function get( $arg );

php/WP_CLI/Fetchers/Signup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Signup extends Base {
1818
* Get a signup.
1919
*
2020
* @param int|string $signup
21-
* @return stdClass|false
21+
* @return object|false
2222
*/
2323
public function get( $signup ) {
2424
return $this->get_signup( $signup );
@@ -28,7 +28,7 @@ public function get( $signup ) {
2828
* Get a signup by one of its identifying attributes.
2929
*
3030
* @param string $arg The raw CLI argument.
31-
* @return stdClass|false The item if found; false otherwise.
31+
* @return object|false The item if found; false otherwise.
3232
*/
3333
protected function get_signup( $arg ) {
3434
global $wpdb;

php/WP_CLI/FileCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ protected function ensure_dir_exists( $dir ) {
328328
if ( ! @mkdir( $dir, 0777, true ) ) {
329329
$message = "Failed to create directory '{$dir}'";
330330
$error = error_get_last();
331-
if ( is_array( $error ) && array_key_exists( 'message', $error ) ) {
331+
if ( is_array( $error ) ) {
332332
$message .= ": {$error['message']}";
333333
}
334334
WP_CLI::warning( "{$message}." );

php/WP_CLI/Formatter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ private function show_multiple_fields( $data, $format, $ascii_pre_colorized = fa
286286

287287
default:
288288
WP_CLI::error( 'Invalid format: ' . $format );
289-
break;
290289

291290
}
292291
}

php/WP_CLI/Inflector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ public static function pluralize( $word ) {
491491
return self::$cache['pluralize'][ $word ];
492492
}
493493
}
494+
495+
// Just so a string is always returned.
496+
// This should never be reached.
497+
return $word;
494498
}
495499

496500
/**

0 commit comments

Comments
 (0)