From 7daea873a29e6101175a9f76c20e84e1ac5dbb40 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 3 Dec 2023 20:09:04 +0000 Subject: [PATCH] Replaced `call_user_func*` with native calls --- src/EachPromise.php | 8 +++----- tests/CoroutineTest.php | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/EachPromise.php b/src/EachPromise.php index 28dd979..e123898 100644 --- a/src/EachPromise.php +++ b/src/EachPromise.php @@ -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. @@ -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 @@ -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 diff --git a/tests/CoroutineTest.php b/tests/CoroutineTest.php index a2bffdd..f046e15 100644 --- a/tests/CoroutineTest.php +++ b/tests/CoroutineTest.php @@ -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()