| Total Complexity | 9 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class EventCounterDeprecated extends TimedCounterDeprecated |
||
|
|
|||
| 14 | { |
||
| 15 | /** @var array */ |
||
| 16 | protected $events = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param int|null $time |
||
| 20 | */ |
||
| 21 | 17 | public function addEvent(?int $time = null): void |
|
| 22 | { |
||
| 23 | 17 | $time = $this->getBaseTime($time); |
|
| 24 | // Is there any event during [$time] period? If not initialize with 0 |
||
| 25 | 17 | $this->events[$time] = $this->events[$time] ?? 0; |
|
| 26 | 17 | $this->events[$time]++; |
|
| 27 | 17 | $this->trim(); |
|
| 28 | 17 | } |
|
| 29 | |||
| 30 | 17 | private function trim(): void |
|
| 35 | } |
||
| 36 | 17 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @param bool|null $reset |
||
| 40 | * @return int |
||
| 41 | */ |
||
| 42 | 4 | public function getCalculatedEvents(?bool $reset = null): int |
|
| 43 | { |
||
| 44 | 4 | $r = 0; |
|
| 45 | 4 | if (0 < ($sum = (int)array_sum($this->events))) { |
|
| 46 | 4 | $r = $sum; |
|
| 47 | } |
||
| 48 | 4 | if ($reset) { |
|
| 49 | 2 | $this->reset(); |
|
| 50 | } |
||
| 51 | 4 | return $r; |
|
| 52 | } |
||
| 53 | |||
| 54 | 2 | protected function reset(): void |
|
| 55 | { |
||
| 56 | 2 | $this->events = []; |
|
| 57 | 2 | } |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | 3 | public function getRawEventsData(): array |
|
| 65 | } |
||
| 66 | } |
||
| 67 |