Skip to content

Commit 9abc7fc

Browse files
authored
Merge pull request #5283 from wp-cli/fix-signature-change-in-upgrader-skin-feedback-method
Add PHP-version-specific traits to extend the upgrader skin feedback method
2 parents 3da5b5b + c8ccab0 commit 9abc7fc

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace WP_CLI\Compat;
4+
5+
// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound,Generic.Classes.DuplicateClassName.Found
6+
7+
if ( PHP_VERSION_ID >= 50600 ) {
8+
require_once __DIR__ . '/Min_PHP_5_6/FeedbackMethodTrait.php';
9+
10+
trait FeedbackMethodTrait {
11+
12+
use Min_PHP_5_6\FeedbackMethodTrait;
13+
}
14+
15+
return;
16+
}
17+
18+
require_once __DIR__ . '/Min_PHP_5_4/FeedbackMethodTrait.php';
19+
20+
trait FeedbackMethodTrait {
21+
22+
use Min_PHP_5_4\FeedbackMethodTrait;
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace WP_CLI\Compat\Min_PHP_5_4;
4+
5+
trait FeedbackMethodTrait {
6+
7+
/**
8+
* @param string $string
9+
*/
10+
public function feedback( $string ) {
11+
$args = func_get_args();
12+
$args = array_splice( $args, 1 );
13+
14+
$this->process_feedback( $string, $args );
15+
}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace WP_CLI\Compat\Min_PHP_5_6;
4+
5+
trait FeedbackMethodTrait {
6+
7+
/**
8+
* @param string $string
9+
* @param mixed ...$args Optional text replacements.
10+
*
11+
*/
12+
public function feedback( $string, ...$args ) { // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ellipsisFound
13+
$args_array = [];
14+
foreach ( $args as $arg ) {
15+
$args_array[] = $args;
16+
}
17+
18+
$this->process_feedback( $string, $args );
19+
}
20+
}

php/WP_CLI/UpgraderSkin.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
class UpgraderSkin extends WP_Upgrader_Skin {
1515

16+
use WP_CLI\Compat\FeedbackMethodTrait;
17+
1618
public $api;
1719

1820
public function header() {}
@@ -33,7 +35,13 @@ public function error( $error ) {
3335
WP_CLI::warning( $error );
3436
}
3537

36-
public function feedback( $string ) {
38+
/**
39+
* Process the feedback collected through the compat indirection.
40+
*
41+
* @param string $string String to use as feedback message.
42+
* @param array $args Array of additional arguments to process.
43+
*/
44+
public function process_feedback( $string, $args ) {
3745

3846
if ( 'parent_theme_prepare_install' === $string ) {
3947
WP_CLI::get_http_cache_manager()->whitelist_package( $this->api->download_link, 'theme', $this->api->slug, $this->api->version );
@@ -43,14 +51,8 @@ public function feedback( $string ) {
4351
$string = $this->upgrader->strings[ $string ];
4452
}
4553

46-
if ( strpos( $string, '%' ) !== false ) {
47-
// Only looking at the arguments from the second one onwards, so this is "safe".
48-
// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed
49-
$args = func_get_args();
50-
$args = array_splice( $args, 1 );
51-
if ( ! empty( $args ) ) {
52-
$string = vsprintf( $string, $args );
53-
}
54+
if ( ! empty( $args ) && strpos( $string, '%' ) !== false ) {
55+
$string = vsprintf( $string, $args );
5456
}
5557

5658
if ( empty( $string ) ) {

0 commit comments

Comments
 (0)