Skip to content

Commit

Permalink
Replaced call_user_func* with native calls
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Dec 3, 2023
1 parent 71b12f9 commit 7daea87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/EachPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function refillPending(): void

// Add only up to N pending promises.
$concurrency = is_callable($this->concurrency)
? call_user_func($this->concurrency, count($this->pending))
? ($this->concurrency)(count($this->pending))
: $this->concurrency;
$concurrency = max($concurrency - count($this->pending), 0);
// Concurrency may be set to 0 to disallow new promises.
Expand Down Expand Up @@ -170,8 +170,7 @@ private function addPending(): bool
$this->pending[$idx] = $promise->then(
function ($value) use ($idx, $key): void {
if ($this->onFulfilled) {
call_user_func(
$this->onFulfilled,
($this->onFulfilled)(
$value,
$key,
$this->aggregate
Expand All @@ -181,8 +180,7 @@ function ($value) use ($idx, $key): void {
},
function ($reason) use ($idx, $key): void {
if ($this->onRejected) {
call_user_func(
$this->onRejected,
($this->onRejected)(
$reason,
$key,
$this->aggregate
Expand Down
4 changes: 2 additions & 2 deletions tests/CoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public function testShouldProxyPromiseMethodsToResultPromise($method, $args = []
{
$coroutine = new Coroutine(function () { yield 0; });
$mockPromise = $this->getMockForAbstractClass(PromiseInterface::class);
call_user_func_array([$mockPromise->expects($this->once())->method($method), 'with'], $args);
$mockPromise->expects($this->once())->method($method)->with(...$args);

$resultPromiseProp = (new ReflectionClass(Coroutine::class))->getProperty('result');
$resultPromiseProp->setAccessible(true);
$resultPromiseProp->setValue($coroutine, $mockPromise);

call_user_func_array([$coroutine, $method], $args);
$coroutine->{$method}(...$args);
}

public function promiseInterfaceMethodProvider()
Expand Down

0 comments on commit 7daea87

Please sign in to comment.