Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class ProgressByRatio extends Progress |
||
11 | { |
||
12 | /** @var float */ |
||
13 | private $ratio; |
||
14 | |||
15 | /** @var int */ |
||
16 | private $precision; |
||
17 | |||
18 | /** |
||
19 | * ProgressByRatio constructor. |
||
20 | * |
||
21 | * @param Status|null $status |
||
22 | * @param iterable<SplObserver> $observers |
||
23 | * @param float $ratio |
||
24 | * @param int $precision |
||
25 | */ |
||
26 | public function __construct( |
||
27 | 9 | ?Status $status = null, |
|
28 | iterable $observers = [], |
||
29 | float $ratio = 0.01, |
||
30 | int $precision = 2 |
||
31 | ) { |
||
32 | parent::__construct($status, $observers); |
||
33 | 9 | if ($precision < 0) { |
|
34 | 9 | throw new InvalidArgumentException('Precision must be an positive integer'); |
|
35 | 1 | } |
|
36 | $this->precision = $precision; |
||
37 | 8 | $this->ratio = max(round($ratio, $this->precision), 10 ** (-$this->precision)); |
|
38 | 8 | } |
|
39 | |||
40 | /** @noinspection PhpMissingParentCallCommonInspection */ |
||
41 | public function shouldNotifyChange(Status $current, Status $newStatus): bool |
||
46 | 1 | } |
|
47 | |||
48 | public function getRatio(): float |
||
51 | 5 | } |
|
52 | |||
53 | public function getPrecision(): int |
||
58 |