Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"wp-cli/wp-cli": "^2.12"
"wp-cli/wp-cli": "^2.13"
},
"require-dev": {
"wp-cli/db-command": "^1.3 || ^2",
Expand Down
3 changes: 3 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@
<exclude-pattern>*/src/Language_Namespace\.php$</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>*/tests/phpstan</exclude-pattern>
</rule>
</ruleset>
4 changes: 1 addition & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
- vendor/wp-cli/wp-cli/php
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
- tests/phpstan/scan-files.php
treatPhpDocTypesAsCertain: false
strictRules:
uselessCast: true
Expand All @@ -16,7 +17,4 @@ parameters:
numericOperandsInArithmeticOperators: true
switchConditionsMatchingType: true
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.property
- identifier: missingType.parameter
- identifier: missingType.return
3 changes: 3 additions & 0 deletions src/Core_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ public function activate( $args ) {
$this->activate_language( $language_code );
}

/**
* @param string $language_code
*/
private function activate_language( $language_code ) {
$available = $this->get_installed_languages();

Expand Down
13 changes: 8 additions & 5 deletions src/Plugin_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,18 @@ public function install( $args, $assoc_args ) {
if ( $all ) {
$this->install_many( $args, $assoc_args );
} else {
/**
* @var non-empty-list<string> $args
*/
$this->install_one( $args, $assoc_args );
}
}

/**
* Installs translations for a plugin.
*
* @param array $args Runtime arguments.
* @param array $assoc_args Runtime arguments.
* @param non-empty-list<string> $args Positional arguments.
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
*/
private function install_one( $args, $assoc_args ) {
$plugin = array_shift( $args );
Expand Down Expand Up @@ -314,8 +317,8 @@ private function install_one( $args, $assoc_args ) {
/**
* Installs translations for all installed plugins.
*
* @param array $args Runtime arguments.
* @param array $assoc_args Runtime arguments.
* @param string[] $args Positional arguments.
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
*/
private function install_many( $args, $assoc_args ) {
$language_codes = (array) $args;
Expand Down Expand Up @@ -627,7 +630,7 @@ public function update( $args, $assoc_args ) {
* Uses the same filter core uses in plugins.php to determine which plugins
* should be available to manage through the WP_Plugins_List_Table class.
*
* @return array
* @return array<string, array{Name: string}>
*/
private function get_all_plugins() {
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Using WP native hook.
Expand Down
3 changes: 3 additions & 0 deletions src/Site_Switch_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Site_Switch_Language_Command extends WP_CLI\CommandWithTranslation {
* Success: Language activated.
*
* @throws WP_CLI\ExitException
*
* @param array{0: string} $args Positional arguments.
* @param array<mixed> $assoc_args Associative arguments.
*/
public function __invoke( $args, $assoc_args ) {
list( $language_code ) = $args;
Expand Down
11 changes: 7 additions & 4 deletions src/Theme_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,18 @@ public function install( $args, $assoc_args ) {
if ( $all ) {
$this->install_many( $args, $assoc_args );
} else {
/**
* @var non-empty-list<string> $args
*/
$this->install_one( $args, $assoc_args );
}
}

/**
* Installs translations for a theme.
*
* @param array $args Runtime arguments.
* @param array $assoc_args Runtime arguments.
* @param non-empty-list<string> $args Positional arguments.
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
*/
private function install_one( $args, $assoc_args ) {
$theme = array_shift( $args );
Expand Down Expand Up @@ -318,8 +321,8 @@ private function install_one( $args, $assoc_args ) {
/**
* Installs translations for all installed themes.
*
* @param array $args Runtime arguments.
* @param array $assoc_args Runtime arguments.
* @param string[] $args Positional arguments.
* @param array{all?: bool, format: string} $assoc_args Associative arguments.
*/
private function install_many( $args, $assoc_args ) {
$language_codes = (array) $args;
Expand Down
23 changes: 20 additions & 3 deletions src/WP_CLI/CommandWithTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@
* @package wp-cli
*/
abstract class CommandWithTranslation extends WP_CLI_Command {
/**
* @var string
*/
protected $obj_type;

/**
* @var string[]
*/
protected $obj_fields;

/**
* Callback to sort array by a 'language' key.
*
* @param array{language: string, english_name: string, native_name: string, updated: string} $a
* @param array{language: string, english_name: string, native_name: string, updated: string} $b
*/
protected function sort_translations_callback( $a, $b ) {
return strnatcasecmp( $a['language'], $b['language'] );
Expand Down Expand Up @@ -66,7 +75,7 @@ public function update( $args, $assoc_args ) {
$plugins = get_plugins( '/' . $update->slug );

/**
* @var array{Name: string}> $plugin_data
* @var array{Name: string} $plugin_data
*/
$plugin_data = array_shift( $plugins );
$name = $plugin_data['Name'];
Expand Down Expand Up @@ -115,6 +124,8 @@ public function update( $args, $assoc_args ) {
*/
$upgrader_instance = Utils\get_upgrader( $upgrader );

// Wrong docblock in core.
// @phpstan-ignore argument.type
$result = $upgrader_instance->upgrade( $update );

$results[] = $result;
Expand Down Expand Up @@ -157,7 +168,7 @@ public function update( $args, $assoc_args ) {
*
* @see wp_get_translation_updates()
*
* @return array
* @return array<object{type: string, slug: string, language: string}&\stdClass>
*/
protected function get_translation_updates() {
$available = $this->get_installed_languages();
Expand Down Expand Up @@ -202,7 +213,7 @@ protected function get_translation_updates() {
$updates = array();

/**
* @var object{translations: array} $transient
* @var object{translations: list<array{type: string, slug: string, language: string}>} $transient
*/
$transient = get_site_transient( $transient );

Expand All @@ -214,6 +225,10 @@ protected function get_translation_updates() {
$updates[] = (object) $translation;
}

/**
* @var array<object{type: string, slug: string, language: string}&\stdClass> $updates
*/

return $updates;
}

Expand Down Expand Up @@ -376,6 +391,8 @@ protected function get_all_languages( $slug = null ) {
*
* @param array $assoc_args Parameters passed to command. Determines formatting.
* @return Formatter
*
* @phpstan-ignore missingType.iterableValue
*/
protected function get_formatter( &$assoc_args ) {
return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
Expand Down
2 changes: 2 additions & 0 deletions src/WP_CLI/LanguagePackUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function generic_strings() {
* @param bool $check_signatures Whether to validate file signatures. Default false.
* @param array $hook_extra Extra arguments to pass to the filter hooks. Default empty array.
* @return string|\WP_Error The full path to the downloaded package file, or a WP_Error object.
*
* @phpstan-ignore missingType.iterableValue
*/
public function download_package( $package, $check_signatures = false, $hook_extra = [] ) {

Expand Down
3 changes: 3 additions & 0 deletions tests/phpstan/scan-files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

define( 'WPINC', '' );