Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Use argument unpacking instead of call_user_func #280

Merged
merged 1 commit into from
Nov 8, 2016
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 lib/Doctrine/MongoDB/Aggregation/Stage/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function geoWithinCenterSphere($x, $y, $radius)
*/
public function geoWithinPolygon(/* array($x1, $y1), ... */)
{
call_user_func_array([$this->query, 'geoWithinPolygon'], func_get_args());
$this->query->geoWithinPolygon(...func_get_args());

return $this;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/Doctrine/MongoDB/Aggregation/Stage/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function abs($number)
*/
public function add($expression1, $expression2 /* , $expression3, ... */)
{
call_user_func_array([$this->expr, 'add'], func_get_args());
$this->expr->add(...func_get_args());

return $this;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public function cmp($expression1, $expression2)
*/
public function concat($expression1, $expression2 /* , $expression3, ... */)
{
call_user_func_array([$this->expr, 'concat'], func_get_args());
$this->expr->concat(...func_get_args());

return $this;
}
Expand All @@ -253,7 +253,7 @@ public function concat($expression1, $expression2 /* , $expression3, ... */)
*/
public function concatArrays($array1, $array2 /* , $array3, ... */)
{
call_user_func_array([$this->expr, 'concatArrays'], func_get_args());
$this->expr->concatArrays(...func_get_args());

return $this;
}
Expand Down Expand Up @@ -822,7 +822,7 @@ public function month($expression)
*/
public function multiply($expression1, $expression2 /* , $expression3, ... */)
{
call_user_func_array([$this->expr, 'multiply'], func_get_args());
$this->expr->multiply(...func_get_args());

return $this;
}
Expand Down Expand Up @@ -935,7 +935,7 @@ public function setDifference($expression1, $expression2)
*/
public function setEquals($expression1, $expression2 /* , $expression3, ... */)
{
call_user_func_array([$this->expr, 'setEquals'], func_get_args());
$this->expr->setEquals(...func_get_args());

return $this;
}
Expand All @@ -955,7 +955,7 @@ public function setEquals($expression1, $expression2 /* , $expression3, ... */)
*/
public function setIntersection($expression1, $expression2 /* , $expression3, ... */)
{
call_user_func_array([$this->expr, 'setIntersection'], func_get_args());
$this->expr->setIntersection(...func_get_args());

return $this;
}
Expand All @@ -975,7 +975,7 @@ public function setIntersection($expression1, $expression2 /* , $expression3, ..
*/
public function setIsSubset($expression1, $expression2)
{
call_user_func_array([$this->expr, 'setIsSubset'], func_get_args());
$this->expr->setIsSubset($expression1, $expression2);

return $this;
}
Expand All @@ -995,7 +995,7 @@ public function setIsSubset($expression1, $expression2)
*/
public function setUnion($expression1, $expression2 /* , $expression3, ... */)
{
call_user_func_array([$this->expr, 'setUnion'], func_get_args());
$this->expr->setUnion(...func_get_args());

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/MongoDB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function listDatabases()
public function log(array $log)
{
if (null !== $this->config->getLoggerCallable()) {
call_user_func_array($this->config->getLoggerCallable(), [$log]);
call_user_func($this->config->getLoggerCallable(), $log);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/MongoDB/LoggableDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(Connection $connection, \MongoDB $mongoDB, EventMana
public function log(array $log)
{
$log['db'] = $this->getName();
call_user_func_array($this->loggerCallable, [$log]);
call_user_func($this->loggerCallable, $log);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/MongoDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ public function geoWithinCenterSphere($x, $y, $radius)
*/
public function geoWithinPolygon(/* array($x1, $y1), ... */)
{
call_user_func_array([$this->expr, 'geoWithinPolygon'], func_get_args());
$this->expr->geoWithinPolygon(...func_get_args());
return $this;
}

Expand Down Expand Up @@ -1896,7 +1896,7 @@ public function withinCenterSphere($x, $y, $radius)
*/
public function withinPolygon(/* array($x1, $y1), array($x2, $y2), ... */)
{
call_user_func_array([$this->expr, 'withinPolygon'], func_get_args());
$this->expr->withinPolygon(...func_get_args());
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/MongoDB/Traits/LoggableCollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function log(array $log)
{
$log['db'] = $this->database->getName();
$log['collection'] = $this->getName();
call_user_func_array($this->loggerCallable, [$log]);
call_user_func($this->loggerCallable, $log);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions tests/Doctrine/MongoDB/Tests/Aggregation/Stage/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class GroupTest extends \PHPUnit_Framework_TestCase
public function testProxiedExprMethods($method, array $args = [])
{
$expr = $this->getMockAggregationExpr();
$invocationMocker = $expr->expects($this->once())->method($method);
call_user_func_array([$invocationMocker, 'with'], $args);
$expr
->expects($this->once())
->method($method)
->with(...$args);

$stage = new GroupStub($this->getTestAggregationBuilder());
$stage->setQuery($expr);

$this->assertSame($stage, call_user_func_array([$stage, $method], $args));
$this->assertSame($stage, $stage->$method(...$args));
}

public function provideProxiedExprMethods()
Expand Down
8 changes: 5 additions & 3 deletions tests/Doctrine/MongoDB/Tests/Aggregation/Stage/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public function testMatchFromBuilder()
public function testProxiedExprMethods($method, array $args = [])
{
$expr = $this->getMockQueryExpr();
$invocationMocker = $expr->expects($this->once())->method($method);
call_user_func_array([$invocationMocker, 'with'], $args);
$expr
->expects($this->once())
->method($method)
->with(...$args);

$stage = $this->getStubStage();
$stage->setQuery($expr);

$this->assertSame($stage, call_user_func_array([$stage, $method], $args));
$this->assertSame($stage, $stage->$method(...$args));
}

public function provideProxiedExprMethods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class OperatorTest extends \PHPUnit_Framework_TestCase
public function testProxiedExprMethods($method, array $args = [])
{
$expr = $this->getMockAggregationExpr();
$invocationMocker = $expr->expects($this->once())->method($method);
call_user_func_array([$invocationMocker, 'with'], $args);
$expr
->expects($this->once())
->method($method)
->with(...$args);

$stage = $this->getStubStage();
$stage->setQuery($expr);

$this->assertSame($stage, call_user_func_array([$stage, $method], $args));
$this->assertSame($stage, $stage->$method(...$args));
}

public function provideProxiedExprMethods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ public function provideAccumulators()
public function testProxiedExprMethods($method, array $args = [])
{
$expr = $this->getMockAggregationExpr();
$invocationMocker = $expr->expects($this->once())->method($method);
call_user_func_array([$invocationMocker, 'with'], $args);
$expr
->expects($this->once())
->method($method)
->with(...$args);

$stage = new GroupStub($this->getTestAggregationBuilder());
$stage->setQuery($expr);

$this->assertSame($stage, call_user_func_array([$stage, $method], $args));
$this->assertSame($stage, $stage->$method(...$args));
}

public static function provideProxiedExprMethods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ private function getMockCollection(EventManager $eventManager, array $methods)
->getMock();

foreach ($methods as $method => $withValues) {
$expectation = $collection->expects($this->once());
$expectation->method($method);
call_user_func_array([$expectation, 'with'], $withValues);
$collection
->expects($this->once())
->method($method)
->with(...$withValues);
}

return $collection;
Expand Down
12 changes: 7 additions & 5 deletions tests/Doctrine/MongoDB/Tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,15 @@ public function testDeepClone()
public function testProxiedExprMethods($method, array $args = [])
{
$expr = $this->getMockExpr();
$invocationMocker = $expr->expects($this->once())->method($method);
call_user_func_array([$invocationMocker, 'with'], $args);
$expr
->expects($this->once())
->method($method)
->with(...$args);

$qb = $this->getStubQueryBuilder();
$qb->setExpr($expr);

$this->assertSame($qb, call_user_func_array([$qb, $method], $args));
$this->assertSame($qb, $qb->$method(...$args));
}

public function provideProxiedExprMethods()
Expand Down Expand Up @@ -540,7 +542,7 @@ public function testSphericalRequiresGeoNearCommand()
public function testSelect(array $args, array $expected)
{
$qb = $this->getTestQueryBuilder();
call_user_func_array([$qb, 'select'], $args);
$qb->select(...$args);

$this->assertEquals($expected, $qb->debug('select'));
}
Expand All @@ -556,7 +558,7 @@ public function provideSelectProjections()
public function testExclude(array $args, array $expected)
{
$qb = $this->getTestQueryBuilder();
call_user_func_array([$qb, 'exclude'], $args);
$qb->exclude(...$args);

$this->assertEquals($expected, $qb->debug('select'));
}
Expand Down