Skip to content

Commit 8ffd0cf

Browse files
authored
Use class instead of static variables for the speed measurement (#168)
1 parent b2c601b commit 8ffd0cf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/cli/Notify.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ abstract class Notify {
3030
protected $_message;
3131
protected $_start;
3232
protected $_timer;
33+
protected $_tick;
34+
protected $_iteration = 0;
35+
protected $_speed = 0;
3336

3437
/**
3538
* Instatiates a Notification object.
@@ -92,23 +95,21 @@ public function elapsed() {
9295
* @return int The number of ticks performed in 1 second.
9396
*/
9497
public function speed() {
95-
static $tick, $iteration = 0, $speed = 0;
96-
9798
if (!$this->_start) {
9899
return 0;
99-
} else if (!$tick) {
100-
$tick = $this->_start;
100+
} else if (!$this->_tick) {
101+
$this->_tick = $this->_start;
101102
}
102103

103104
$now = microtime(true);
104-
$span = $now - $tick;
105+
$span = $now - $this->_tick;
105106
if ($span > 1) {
106-
$iteration++;
107-
$tick = $now;
108-
$speed = ($this->_current / $iteration) / $span;
107+
$this->_iteration++;
108+
$this->_tick = $now;
109+
$this->_speed = ($this->_current / $this->_iteration) / $span;
109110
}
110111

111-
return $speed;
112+
return $this->_speed;
112113
}
113114

114115
/**

0 commit comments

Comments
 (0)