Total Complexity | 5 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
10 | class ProgressJuggler implements JugglerInterface |
||
11 | { |
||
12 | /** @var string */ |
||
13 | protected $spacer = Defaults::ONE_SPACE_SYMBOL; |
||
14 | /** @var string */ |
||
15 | protected $currentFrame; |
||
16 | /** @var int */ |
||
17 | protected $currentFrameErasingLength; |
||
18 | /** @var Circular */ |
||
19 | protected $style; |
||
20 | |||
21 | 11 | public function __construct(float $percent, Circular $style = null) |
|
22 | { |
||
23 | 11 | $this->style = $style ?? new Circular(['%s',]); |
|
24 | 11 | $this->update($percent); |
|
25 | 11 | } |
|
26 | |||
27 | /** |
||
28 | * @param float $percent |
||
29 | */ |
||
30 | 11 | protected function update(float $percent): void |
|
31 | { |
||
32 | 11 | $progress = bounds($percent, 0, 1); |
|
33 | 11 | $this->currentFrame = (int)($progress * 100) . '%' . $this->spacer; |
|
34 | 11 | $this->currentFrameErasingLength = strlen($this->currentFrame); |
|
35 | 11 | } |
|
36 | |||
37 | /** |
||
38 | * @param float $percent |
||
39 | */ |
||
40 | 10 | public function setProgress(float $percent): void |
|
41 | { |
||
42 | 10 | $this->update($percent); |
|
43 | 10 | } |
|
44 | |||
45 | /** {@inheritDoc} */ |
||
46 | 11 | public function getStyledFrame(): string |
|
50 | } |
||
51 | |||
52 | /** {@inheritDoc} */ |
||
53 | 11 | public function getFrameErasingLength(): int |
|
58 | } |
||
59 | } |
||
60 |