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