Passed
Push — master ( 89e51d...1f5b35 )
by Alec
17:10 queued 14:17
created

SpinnerCore   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 3
b 0
f 0
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A disable() 0 4 1
A refineOutput() 0 7 2
A enable() 0 4 1
A isActive() 0 3 1
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 1
    public function isActive(): bool
55
    {
56 1
        return $this->enabled;
57
    }
58
}
59