Passed
Push — master ( a0dc40...285a03 )
by Alec
03:52
created

TimeSpinner::begin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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 TimeSpinner extends Spinner
11
{
12
    protected const INTERVAL = 1;
13
    protected const FRAMES = null;
14
    protected const
15
        STYLES =
16
        [
17
            StylesInterface::SPINNER_STYLES =>
18
                [
19
                    StylesInterface::COLOR256 => StylesInterface::DISABLED,
20
                    StylesInterface::COLOR => StylesInterface::DISABLED,
21
                ],
22
        ];
23
24
    /** @var string */
25
    protected $timeFormat = 'T Y-m-d H:i:s';
26
27
    /**
28
     * @param string $timeFormat
29
     * @return TimeSpinner
30
     */
31
    public function setTimeFormat(string $timeFormat): TimeSpinner
32
    {
33
        $this->timeFormat = $timeFormat;
34
        return $this;
35
    }
36
37
    /** {@inheritDoc} */
38
    public function spin(?float $percent = null, ?string $message = null): string
39
    {
40
        return parent::spin(null, date($this->timeFormat) ?: '');
41
    }
42
43
    /** {@inheritDoc} */
44
    public function begin(?float $percent = null): string
45
    {
46
        return parent::begin();
47
    }
48
49
    /** {@inheritDoc} */
50
    protected function defaultSettings(): SettingsInterface
51
    {
52
        return
53
            parent::defaultSettings()
54
                ->setMessagePrefix(SettingsInterface::EMPTY)
55
                ->setMessageSuffix(SettingsInterface::EMPTY);
56
    }
57
}
58