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