Passed
Push — master ( 7b0af7...e2bdc6 )
by Alec
03:09
created

ProgressJuggler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 5 1
A setProgress() 0 3 1
A getCurrentFrame() 0 3 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core\Jugglers;
4
5
use AlecRabbit\Accessories\Circular;
6
use AlecRabbit\Spinner\Settings\Contracts\Defaults;
7
use function AlecRabbit\Helpers\bounds;
8
9
class ProgressJuggler extends AbstractJuggler
10
{
11
    /** @var string */
12
    protected $spacer = Defaults::ONE_SPACE_SYMBOL;
13
    /** @var string */
14
    protected $currentFrame;
15
16 11
    public function __construct(float $percent, Circular $style = null)
17
    {
18 11
        $this->style = $style ?? new Circular(['%s',]);
19 11
        $this->update($percent);
20 11
    }
21
22
    /**
23
     * @param float $percent
24
     */
25 11
    protected function update(float $percent): void
26
    {
27 11
        $progress = bounds($percent, 0, 1);
28 11
        $this->currentFrame = $this->prefix. (int)($progress * 100) . '%' . $this->suffix . $this->spacer;
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
29 11
        $this->currentFrameErasingLength = strlen($this->currentFrame);
30 11
    }
31
32
    /**
33
     * @param float $percent
34
     */
35 10
    public function setProgress(float $percent): void
36
    {
37 10
        $this->update($percent);
38 10
    }
39
40
    /**
41
     * @return string
42
     */
43 11
    protected function getCurrentFrame(): string
44
    {
45 11
        return $this->currentFrame;
46
    }
47
}
48