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

ProgressJuggler::getCurrentFrame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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