diff --git a/composer.json b/composer.json index fbb7de7..72c0cdb 100644 --- a/composer.json +++ b/composer.json @@ -2,12 +2,12 @@ "name": "zwirek/react-timer-handler", "type": "library", "description": "Simple handler for ReactPHP timers", - "keywords": ["ReactPHP", "Timer", "react", "handler"], + "keywords": ["ReactPHP", "Timer", "react", "handler", "php", "async"], "license": "MIT", "authors": [ { "name": "Zbigniew Żwirek", - "email": "git.srv@zwirek.net" + "email": "github.srv@zwirek.net" } ], "autoload": { @@ -21,10 +21,10 @@ } }, "require": { - "php": "^7.1", + "php": ">=8.1", "react/event-loop": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^8.2 || ^7.0 || ^6.4 || ^5.7" + "phpunit/phpunit": "^8.2" } } diff --git a/src/TimerHandler.php b/src/TimerHandler.php index 145c332..48cc608 100644 --- a/src/TimerHandler.php +++ b/src/TimerHandler.php @@ -11,17 +11,17 @@ final class TimerHandler implements TimerHandlerInterface /** * @var LoopInterface */ - private $loop; + private LoopInterface $loop; /** * @var TimerInterface[] */ - private $timers = []; + private array $timers = []; /** * @var int[] */ - private $limitedPeriodicTimerCounters = []; + private array $limitedPeriodicTimerCounters = []; public function __construct(LoopInterface $loop) { @@ -43,7 +43,7 @@ public function addTimer(string $name, $interval, callable $callback): bool $this->timers[$name] = null; unset($this->timers[$name]); - call_user_func($callback, $timer); + $callback($timer); }); return true; @@ -106,9 +106,9 @@ public function addLimitedPeriodicTimer(string $name, $interval, callable $callb $this->limitedPeriodicTimerCounters[$name] = 0; $this->timers[$name] = $this->loop->addPeriodicTimer($interval, function (TimerInterface $timer) use ($callback, $name, $callLimit) { - call_user_func($callback, $timer); + $callback($timer); - if (++$this->limitedPeriodicTimerCounters >= $callLimit) { + if (++$this->limitedPeriodicTimerCounters[$name] >= $callLimit) { $this->loop->cancelTimer($timer); $this->timers[$name] = null; unset($this->timers[$name]); diff --git a/tests/TimerHandlerTest.php b/tests/TimerHandlerTest.php index 642a325..9631731 100644 --- a/tests/TimerHandlerTest.php +++ b/tests/TimerHandlerTest.php @@ -76,10 +76,10 @@ public function shouldPassBindParameters() { $timerHandler = new TimerHandler($this->loop); - $parameter = 'binded parameter'; + $parameter = 'bound parameter'; $timerHandler->addTimer('test', 0.005, function() use ($parameter) { - self::assertEquals('bind parameter', $parameter); + self::assertEquals('bound parameter', $parameter); $this->assertLoop(); }); @@ -157,7 +157,7 @@ public function shouldCallTimerAFewTimes() $timerHandler->addLimitedPeriodicTimer('limited', 0.005, function() use (&$counter) { $counter++; - if ($counter = 5) { + if ($counter === 5) { $this->assertLoop(); } }, 5);