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
23 changes: 23 additions & 0 deletions php/WP_CLI/Compat/FeedbackMethodTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace WP_CLI\Compat;

// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound,Generic.Classes.DuplicateClassName.Found

if ( PHP_VERSION_ID >= 50600 ) {
require_once __DIR__ . '/Min_PHP_5_6/FeedbackMethodTrait.php';

trait FeedbackMethodTrait {

use Min_PHP_5_6\FeedbackMethodTrait;
}

return;
}

require_once __DIR__ . '/Min_PHP_5_4/FeedbackMethodTrait.php';

trait FeedbackMethodTrait {

use Min_PHP_5_4\FeedbackMethodTrait;
}
16 changes: 16 additions & 0 deletions php/WP_CLI/Compat/Min_PHP_5_4/FeedbackMethodTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace WP_CLI\Compat\Min_PHP_5_4;

trait FeedbackMethodTrait {

/**
* @param string $string
*/
public function feedback( $string ) {
$args = func_get_args();
$args = array_splice( $args, 1 );

$this->process_feedback( $string, $args );
}
}
20 changes: 20 additions & 0 deletions php/WP_CLI/Compat/Min_PHP_5_6/FeedbackMethodTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace WP_CLI\Compat\Min_PHP_5_6;

trait FeedbackMethodTrait {

/**
* @param string $string
* @param mixed ...$args Optional text replacements.
*
*/
public function feedback( $string, ...$args ) { // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ellipsisFound
$args_array = [];
foreach ( $args as $arg ) {
$args_array[] = $args;
}

$this->process_feedback( $string, $args );
}
}
20 changes: 11 additions & 9 deletions php/WP_CLI/UpgraderSkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class UpgraderSkin extends WP_Upgrader_Skin {

use WP_CLI\Compat\FeedbackMethodTrait;

public $api;

public function header() {}
Expand All @@ -33,7 +35,13 @@ public function error( $error ) {
WP_CLI::warning( $error );
}

public function feedback( $string ) {
/**
* Process the feedback collected through the compat indirection.
*
* @param string $string String to use as feedback message.
* @param array $args Array of additional arguments to process.
*/
public function process_feedback( $string, $args ) {

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

if ( strpos( $string, '%' ) !== false ) {
// Only looking at the arguments from the second one onwards, so this is "safe".
// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args );
}
if ( ! empty( $args ) && strpos( $string, '%' ) !== false ) {
$string = vsprintf( $string, $args );
}

if ( empty( $string ) ) {
Expand Down