ProgressByHit::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\RfcLinc\Application\Cli;
6
7
use EngineWorks\ProgressStatus\Progress;
8
use EngineWorks\ProgressStatus\Status;
9
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)
16
    {
17 8
        parent::__construct($initialStatus, $observers);
18 8
        $this->setHits($hits);
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()
46
    {
47 8
        $observers = parent::getObservers();
48 8
        return $observers;
49
    }
50
}
51