Passed
Push — master ( 4505d6...4505d6 )
by Alec
02:17
created

ProgressJuggler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 2
b 0
f 0
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFrameErasingLength() 0 4 1
A update() 0 4 1
A setProgress() 0 3 1
A getFrame() 0 3 1
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core\Jugglers;
4
5
use AlecRabbit\Spinner\Core\Jugglers\Contracts\JugglerInterface;
6
use AlecRabbit\Spinner\Settings\Contracts\Defaults;
7
use function AlecRabbit\Helpers\bounds;
8
9
class ProgressJuggler implements JugglerInterface
10
{
11
    /** @var float */
12
    protected $progress;
13
    /** @var string */
14
    protected $percentSpacer = Defaults::ONE_SPACE_SYMBOL;
15
    /** @var string */
16
    protected $currentFrame;
17
18 8
    public function __construct(float $percent)
19
    {
20 8
        $this->update($percent);
21 8
    }
22
23 7
    public function setProgress(float $percent): void
24
    {
25 7
        $this->update($percent);
26 7
    }
27
28 8
    public function getFrame(): string
29
    {
30 8
        return $this->currentFrame;
31
    }
32
33 8
    public function getFrameErasingLength(): int
34
    {
35
        return
36 8
            strlen($this->currentFrame);
37
    }
38
39
    /**
40
     * @param float $percent
41
     */
42 8
    protected function update(float $percent): void
43
    {
44 8
        $this->progress = bounds($percent, 0, 1);
45 8
        $this->currentFrame = $this->percentSpacer . (int)($this->progress * 100) . '% ';
46 8
    }
47
}
48