Skip to content

Commit 7696bdc

Browse files
authored
Merge pull request #1 from zwirek/feature/update
fix code and update dependencies
2 parents a0a1a90 + 3a209af commit 7696bdc

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "zwirek/react-timer-handler",
33
"type": "library",
44
"description": "Simple handler for ReactPHP timers",
5-
"keywords": ["ReactPHP", "Timer", "react", "handler"],
5+
"keywords": ["ReactPHP", "Timer", "react", "handler", "php", "async"],
66
"license": "MIT",
77
"authors": [
88
{
99
"name": "Zbigniew Żwirek",
10-
"email": "git.srv@zwirek.net"
10+
"email": "github.srv@zwirek.net"
1111
}
1212
],
1313
"autoload": {
@@ -21,10 +21,10 @@
2121
}
2222
},
2323
"require": {
24-
"php": "^7.1",
24+
"php": ">=8.1",
2525
"react/event-loop": "^1.1"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^8.2 || ^7.0 || ^6.4 || ^5.7"
28+
"phpunit/phpunit": "^8.2"
2929
}
3030
}

src/TimerHandler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ final class TimerHandler implements TimerHandlerInterface
1111
/**
1212
* @var LoopInterface
1313
*/
14-
private $loop;
14+
private LoopInterface $loop;
1515

1616
/**
1717
* @var TimerInterface[]
1818
*/
19-
private $timers = [];
19+
private array $timers = [];
2020

2121
/**
2222
* @var int[]
2323
*/
24-
private $limitedPeriodicTimerCounters = [];
24+
private array $limitedPeriodicTimerCounters = [];
2525

2626
public function __construct(LoopInterface $loop)
2727
{
@@ -43,7 +43,7 @@ public function addTimer(string $name, $interval, callable $callback): bool
4343
$this->timers[$name] = null;
4444
unset($this->timers[$name]);
4545

46-
call_user_func($callback, $timer);
46+
$callback($timer);
4747
});
4848

4949
return true;
@@ -106,9 +106,9 @@ public function addLimitedPeriodicTimer(string $name, $interval, callable $callb
106106
$this->limitedPeriodicTimerCounters[$name] = 0;
107107

108108
$this->timers[$name] = $this->loop->addPeriodicTimer($interval, function (TimerInterface $timer) use ($callback, $name, $callLimit) {
109-
call_user_func($callback, $timer);
109+
$callback($timer);
110110

111-
if (++$this->limitedPeriodicTimerCounters >= $callLimit) {
111+
if (++$this->limitedPeriodicTimerCounters[$name] >= $callLimit) {
112112
$this->loop->cancelTimer($timer);
113113
$this->timers[$name] = null;
114114
unset($this->timers[$name]);

tests/TimerHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public function shouldPassBindParameters()
7676
{
7777
$timerHandler = new TimerHandler($this->loop);
7878

79-
$parameter = 'binded parameter';
79+
$parameter = 'bound parameter';
8080

8181
$timerHandler->addTimer('test', 0.005, function() use ($parameter) {
82-
self::assertEquals('bind parameter', $parameter);
82+
self::assertEquals('bound parameter', $parameter);
8383

8484
$this->assertLoop();
8585
});
@@ -157,7 +157,7 @@ public function shouldCallTimerAFewTimes()
157157
$timerHandler->addLimitedPeriodicTimer('limited', 0.005, function() use (&$counter) {
158158
$counter++;
159159

160-
if ($counter = 5) {
160+
if ($counter === 5) {
161161
$this->assertLoop();
162162
}
163163
}, 5);

0 commit comments

Comments
 (0)