Passed
Push — master ( f027ec...3dc7d4 )
by Alec
02:52
created

SpinnerCore::refineOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 2
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core;
4
5
use AlecRabbit\Spinner\Core\Adapters\EchoOutputAdapter;
6
use AlecRabbit\Spinner\Core\Contracts\Frames;
7
use AlecRabbit\Spinner\Core\Contracts\SpinnerInterface;
8
use AlecRabbit\Spinner\Core\Contracts\OutputInterface;
9
use AlecRabbit\Spinner\Core\Contracts\Styles;
10
use AlecRabbit\Spinner\Settings\Contracts\Defaults;
11
use function AlecRabbit\typeOf;
12
13
abstract class SpinnerCore implements SpinnerInterface
14
{
15
    protected const EMPTY_STRING = Defaults::EMPTY_STRING;
16
17
    protected const INTERVAL = Defaults::DEFAULT_INTERVAL;
18
    protected const FRAMES = Frames::BASE;
19
    protected const STYLES = Styles::STYLING_DISABLED;
20
21
    /** @var null|OutputInterface */
22
    protected $output;
23
    /** @var bool */
24
    protected $enabled;
25
26
    /**
27
     * @param null|false|OutputInterface $output
28
     * @return null|OutputInterface
29
     */
30 29
    protected function refineOutput($output): ?OutputInterface
31
    {
32 29
        Sentinel::assertOutput($output);
33 27
        if (false === $output) {
34 23
            return null;
35
        }
36 4
        return $output ?? new EchoOutputAdapter();
37
    }
38
39
    /** {@inheritDoc} */
40 1
    public function disable(): SpinnerInterface
41
    {
42 1
        $this->enabled = false;
43 1
        return $this;
44
    }
45
46
    /** {@inheritDoc} */
47 1
    public function enable(): SpinnerInterface
48
    {
49 1
        $this->enabled = true;
50 1
        return $this;
51
    }
52
53
    /** {@inheritDoc} */
54
    public function isActive(): bool
55
    {
56
        return $this->enabled;
57
    }
58
}
59