diff --git a/src/Timer/Timers.php b/src/Timer/Timers.php index 70adc132..87f8331a 100644 --- a/src/Timer/Timers.php +++ b/src/Timer/Timers.php @@ -58,10 +58,7 @@ public function cancel(TimerInterface $timer) public function getFirst() { // ensure timers are sorted to simply accessing next (first) one - if (!$this->sorted) { - $this->sorted = true; - \asort($this->schedule); - } + $this->ensureTimerAreSorted(); return \reset($this->schedule); } @@ -74,10 +71,7 @@ public function isEmpty() public function tick() { // ensure timers are sorted so we can execute in order - if (!$this->sorted) { - $this->sorted = true; - \asort($this->schedule); - } + $this->ensureTimerAreSorted(); $time = $this->updateTime(); @@ -104,4 +98,12 @@ public function tick() } } } + + private function ensureTimerAreSorted() + { + if (!$this->sorted) { + $this->sorted = true; + \asort($this->schedule); + } + } }