Skip to content

Commit

Permalink
Use spread operator instead of func_get_args (#13699)
Browse files Browse the repository at this point in the history
* Adapt use of the spread operator instead of func_get_args

* [not verified] Adapt use of the spread operator instead of func_get_args (non-verified due to sync package not being phpcs compliant)

* Update Jetpack_IXR_ClientMulticall

* Revert changes to IXR classes until extending class has been updated
  • Loading branch information
kraftbj authored Oct 21, 2019
1 parent 0bee68a commit 1e240a5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 27 deletions.
6 changes: 3 additions & 3 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5537,8 +5537,10 @@ public static function check_privacy( $file ) {

/**
* Helper method for multicall XMLRPC.
*
* @param ...$args Args for the async_call.
*/
public static function xmlrpc_async_call() {
public static function xmlrpc_async_call( ...$args ) {
global $blog_id;
static $clients = array();

Expand All @@ -5552,8 +5554,6 @@ public static function xmlrpc_async_call() {
add_action( 'shutdown', array( 'Jetpack', 'xmlrpc_async_call' ) );
}

$args = func_get_args();

if ( ! empty( $args[0] ) ) {
call_user_func_array( array( $clients[ $client_blog_id ], 'addCall' ), $args );
} elseif ( is_multisite() ) {
Expand Down
3 changes: 1 addition & 2 deletions class.json-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ static function is_falsy( $value ) {
return false;
}

function __construct() {
$args = func_get_args();
function __construct( ...$args ) {
call_user_func_array( array( $this, 'setup_inputs' ), $args );
}

Expand Down
6 changes: 3 additions & 3 deletions modules/comments/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ protected function setup_filters() {
* @param ...
* @return false|string false if it's not a Highlander POST request. The matching credentials slug if it is.
*/
function is_highlander_comment_post() {
function is_highlander_comment_post( ...$args ) {
if ( empty( $_POST['hc_post_as'] ) ) {
return false;
}

if ( func_num_args() ) {
foreach ( func_get_args() as $id_source ) {
if ( $args ) {
foreach ( $args as $id_source ) {
if ( $id_source === $_POST['hc_post_as'] ) {
return $id_source;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/jitm/tests/php/test_JITM.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ protected function mock_filters( $filters ) {
$builder->setNamespace( __NAMESPACE__ )
->setName( 'apply_filters' )
->setFunction(
function() {
$current_args = func_get_args();
function( ...$current_args ) {
foreach ( $this->mocked_filters as $filter ) {
if ( array_slice( $filter, 0, -1 ) === $current_args ) {
return array_pop( $filter );
Expand Down Expand Up @@ -140,9 +139,8 @@ protected function mock_do_action() {
$builder = new MockBuilder();
$builder->setNamespace( __NAMESPACE__ )
->setName( 'do_action' )
->setFunction( function() {
->setFunction( function( ...$args ) {
global $actions;
$args = func_get_args();
$name = array_shift( $args );

if ( is_null( $actions ) ) {
Expand Down
10 changes: 4 additions & 6 deletions packages/status/tests/php/test_Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function test_is_development_mode_filter_bool() {
) );

$this->assertFalse( $this->status->is_development_mode() );

$filters_mock->disable();
}

Expand All @@ -86,7 +86,7 @@ public function test_is_development_mode_filter_bool() {
*/
public function test_is_development_mode_localhost() {
$this->mock_function( 'site_url', 'localhost' );

$filters_mock = $this->mock_filters( array(
array( 'jetpack_development_mode', false, false ),
array( 'jetpack_development_mode', true, true ),
Expand All @@ -101,7 +101,7 @@ public function test_is_development_mode_localhost() {
* @covers Automattic\Jetpack\Status::is_development_mode
*
* @runInSeparateProcess
*/
*/
public function test_is_development_mode_constant() {
$this->mock_function( 'site_url', $this->site_url );
$filters_mock = $this->mock_filters( array(
Expand Down Expand Up @@ -204,9 +204,7 @@ protected function mock_function_with_args( $function_name, $args = array() ) {
$builder->setNamespace( __NAMESPACE__ )
->setName( $function_name )
->setFunction(
function() use ( &$args ) {
$current_args = func_get_args();

function( ...$current_args ) use ( &$args ) {
foreach ( $args as $arg ) {
if ( array_slice( $arg, 0, -1 ) === $current_args ) {
return array_pop( $arg );
Expand Down
6 changes: 2 additions & 4 deletions packages/sync/src/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ function can_add_to_queue( $queue ) {
( ( $queue_size + 1 ) < $this->sync_queue_size_limit );
}

function full_sync_action_handler() {
$args = func_get_args();
function full_sync_action_handler( ...$args ) {
$this->enqueue_action( current_filter(), $args, $this->full_sync_queue );
}

function action_handler() {
$args = func_get_args();
function action_handler( ...$args ) {
$this->enqueue_action( current_filter(), $args, $this->sync_queue );
}

Expand Down
9 changes: 4 additions & 5 deletions sal/class.json-api-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function getInstance() {
}

// protect these methods for singleton
protected function __construct() {
protected function __construct() {
$this->api = WPCOM_JSON_API::init();
}
private function __clone() { }
Expand All @@ -29,11 +29,10 @@ private function __wakeup() { }
*
* Used to construct meta links in API responses
*
* @param mixed $args Optional arguments to be appended to URL
* @param mixed ...$args Optional arguments to be appended to URL
* @return string Endpoint URL
**/
function get_link() {
$args = func_get_args();
function get_link( ...$args ) {
$format = array_shift( $args );
$base = WPCOM_JSON_API__BASE;

Expand Down Expand Up @@ -127,7 +126,7 @@ function get_external_service_link( $external_service, $path = '' ) {
* maximum available version of /animals/%s, e.g. 1.1
*
* This method is used in get_link() to construct meta links for API responses.
*
*
* @param $template_path string The generic endpoint path, e.g. /sites/%s
* @param $path string The current endpoint path, relative to the version, e.g. /sites/12345
* @param $request_method string Request method used to access the endpoint path
Expand Down

0 comments on commit 1e240a5

Please sign in to comment.