Total Complexity | 7 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | class ProgressByHit extends Progress |
||
11 | { |
||
12 | /** @var int */ |
||
13 | private $hits; |
||
14 | |||
15 | 8 | public function __construct(Status $initialStatus = null, array $observers = [], int $hits = 1000) |
|
19 | 7 | } |
|
20 | |||
21 | 5 | public function hits(): int |
|
22 | { |
||
23 | 5 | return $this->hits; |
|
24 | } |
||
25 | |||
26 | 8 | public function setHits(int $hits) |
|
27 | { |
||
28 | 8 | if ($hits < 0) { |
|
29 | 2 | throw new \DomainException('Expected integer greater or equal than zero'); |
|
30 | } |
||
31 | 7 | $this->hits = $hits; |
|
32 | 7 | } |
|
33 | |||
34 | 3 | public function shouldNotifyChange(Status $currentStatus, Status $newStatus): bool |
|
35 | { |
||
36 | 3 | $hits = $this->hits(); |
|
37 | 3 | if (0 === $hits) { |
|
38 | 1 | return false; |
|
39 | } |
||
40 | 3 | $current = floor($currentStatus->getValue() / $hits); |
|
41 | 3 | $new = floor($newStatus->getValue() / $hits); |
|
42 | 3 | return ($current !== $new); |
|
43 | } |
||
44 | |||
45 | 8 | public function getObservers() |
|
49 | } |
||
50 | } |
||
51 |