From 98df359b1bafc8e94c249820b7f89ce4a822435c Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 16 Nov 2023 11:28:41 +0100 Subject: [PATCH] use class instead of static vars --- lib/cli/Notify.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/cli/Notify.php b/lib/cli/Notify.php index a163f96..36dd55f 100644 --- a/lib/cli/Notify.php +++ b/lib/cli/Notify.php @@ -30,6 +30,9 @@ abstract class Notify { protected $_message; protected $_start; protected $_timer; + protected $_tick; + protected $_iteration = 0; + protected $_speed = 0; /** * Instatiates a Notification object. @@ -92,23 +95,21 @@ public function elapsed() { * @return int The number of ticks performed in 1 second. */ public function speed() { - static $tick, $iteration = 0, $speed = 0; - if (!$this->_start) { return 0; - } else if (!$tick) { - $tick = $this->_start; + } else if (!$this->_tick) { + $this->_tick = $this->_start; } $now = microtime(true); - $span = $now - $tick; + $span = $now - $this->_tick; if ($span > 1) { - $iteration++; - $tick = $now; - $speed = ($this->_current / $iteration) / $span; + $this->_iteration++; + $this->_tick = $now; + $this->_speed = ($this->_current / $this->_iteration) / $span; } - return $speed; + return $this->_speed; } /**