Passed
Push — master ( 8b173b...16969d )
by Alec
02:10
created

PercentSpinner::spin()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 3
nop 2
crap 3
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner;
4
5
use AlecRabbit\Spinner\Core\Contracts\SettingsInterface;
6
use AlecRabbit\Spinner\Core\Contracts\StylesInterface;
7
use AlecRabbit\Spinner\Core\Spinner;
8
use function AlecRabbit\typeOf;
9
10
class PercentSpinner extends Spinner
11
{
12
    // protected const ERASING_SHIFT = 1;
13
    protected const INTERVAL = 0.1;
14
    protected const SYMBOLS = null;
15
    protected const
16
        STYLES =
17
        [
18
            StylesInterface::SPINNER_STYLES =>
19
                [
20
                    StylesInterface::COLOR256 => StylesInterface::DISABLED,
21
                    StylesInterface::COLOR => StylesInterface::DISABLED,
22
                ],
23
        ];
24
25 3
    public function spin(?float $percent = null, ?string $message = null): string
26
    {
27 3
        if (!\is_float($percent)) {
28 1
            throw new \RuntimeException('Float percentage value expected ' . typeOf($percent) . ' given.');
29
        }
30 2
        if (null !== $message) {
31 1
            throw new \RuntimeException('Null value expected ' . typeOf($message) . ' given.');
32
        }
33 1
        return parent::spin($percent);
34
    }
35
36 1
    public function begin(?float $percent = null): string
37
    {
38 1
        return parent::begin(0.0);
39
    }
40
41
    /**
42
     * @return SettingsInterface
43
     */
44 4
    protected function defaultSettings(): SettingsInterface
45
    {
46
        return
47 4
            parent::defaultSettings()
48 4
                ->setMessagePrefix(SettingsInterface::EMPTY);
49
    }
50
}
51