Passed
Push — master ( dbaa53...0b91ad )
by Alec
02:46
created

PercentSpinner::spin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner;
4
5
use AlecRabbit\Spinner\Contracts\SettingsInterface;
6
use AlecRabbit\Spinner\Contracts\SpinnerStyles;
7
use AlecRabbit\Spinner\Contracts\StylesInterface;
8
use AlecRabbit\Spinner\Core\Settings;
9
use AlecRabbit\Spinner\Core\Spinner;
10
use function AlecRabbit\typeOf;
11
12
class PercentSpinner extends Spinner
13
{
14
    protected const ERASING_SHIFT = 1;
15
    protected const INTERVAL = 0.1;
16
    protected const SYMBOLS = null;
17
    protected const
18
        STYLES =
19
        [
20
            StylesInterface::COLOR_MESSAGE_STYLES => SpinnerStyles::C_DARK,
21
            StylesInterface::COLOR_PERCENT_STYLES => SpinnerStyles::C_DARK,
22
        ];
23
24
    /**
25
     * @return Settings
26
     */
27
    protected function defaultSettings(): Settings
28
    {
29
        return
30
            parent::defaultSettings()
31
                ->setPrefix(SettingsInterface::EMPTY);
32
    }
33
34
    public function spin(?float $percent = null): string
35
    {
36
        if(!\is_float($percent)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after IF keyword; 0 found
Loading history...
37
            throw new \RuntimeException('Float percentage value expected ' . typeOf($percent) . ' given.');
38
        }
39
        return parent::spin($percent);
40
    }
41
42
    public function begin(?float $percent = null): string
43
    {
44
        return parent::begin(0.0);
45
    }
46
}
47