Passed
Push — master ( 200d88...9b81d7 )
by Alec
02:43 queued 15s
created

ATerminalSettings   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 79
rs 10
wmc 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
isCursorDisabled() 0 3 ?
A hp$0 ➔ getInstance() 0 12 2
A hp$0 ➔ overrideCursor() 0 4 1
A hp$0 ➔ overrideColorMode() 0 4 1
A __construct() 0 8 1
A hp$0 ➔ getSupportedColorModes() 0 3 1
getSupportedColorModes() 0 3 ?
getWidth() 0 3 ?
overrideWidth() 0 4 ?
A hp$0 ➔ getWidth() 0 3 1
A hp$0 ➔ overrideWidth() 0 4 1
overrideSupportedColorModes() 0 5 ?
overrideColorMode() 0 4 ?
A hp$0 ➔ overrideSupportedColorModes() 0 5 1
getInstance() 0 12 ?
A defaultSupportedColorModes() 0 3 1
A hp$0 ➔ isCursorDisabled() 0 3 1
overrideCursor() 0 4 ?
getStyleMode() 0 3 ?
A hp$0 ➔ getStyleMode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
// 09.03.23
5
6
namespace AlecRabbit\Spinner\Core\Defaults\A;
7
8
use AlecRabbit\Spinner\Contract\Cursor;
9
use AlecRabbit\Spinner\Contract\StyleMode;
10
use AlecRabbit\Spinner\Core\Defaults\Contract\IDefaults;
11
use AlecRabbit\Spinner\Core\Defaults\Contract\ITerminalSettings;
12
use AlecRabbit\Spinner\Helper\Asserter;
13
use ArrayObject;
14
use Traversable;
15
16
abstract class ATerminalSettings extends ADefaultsChild implements ITerminalSettings
17
{
18
    protected static Traversable $supportedColorModes;
19
20
    private static ?ITerminalSettings $objInstance = null; // private, singleton
21
22
    final protected function __construct(
23
        IDefaults $parent,
24
        protected StyleMode $colorMode,
25
        protected int $width,
26
        protected Cursor $cursor,
27
    ) {
28
        parent::__construct($parent);
29
        static::$supportedColorModes = $this->defaultSupportedColorModes();
30
    }
31
32
    protected function defaultSupportedColorModes(): ArrayObject
33
    {
34
        return new ArrayObject(StyleMode::cases());
35
    }
36
37
    final public static function getInstance(
38
        IDefaults $parent,
39
        StyleMode $colorMode,
40
        int $width,
41
        Cursor $cursor,
42
    ): ITerminalSettings {
43
        if (null === self::$objInstance) {
44
            self::$objInstance =
45
                new class ($parent, $colorMode, $width, $cursor) extends ATerminalSettings {
46
                };
47
        }
48
        return self::$objInstance;
49
    }
50
51
    public function getStyleMode(): StyleMode
52
    {
53
        return $this->colorMode;
54
    }
55
56
    public function getWidth(): int
57
    {
58
        return $this->width;
59
    }
60
61
    public function overrideColorMode(StyleMode $colorMode): static
62
    {
63
        $this->colorMode = $colorMode;
64
        return $this;
65
    }
66
67
    public function overrideWidth(int $width): static
68
    {
69
        $this->width = $width;
70
        return $this;
71
    }
72
73
    public function isCursorDisabled(): bool
74
    {
75
        return $this->cursor === Cursor::DISABLED;
76
    }
77
78
    public function overrideCursor(Cursor $cursor): static
79
    {
80
        $this->cursor = $cursor;
81
        return $this;
82
    }
83
84
    public function getSupportedColorModes(): Traversable
85
    {
86
        return static::$supportedColorModes;
87
    }
88
89
    /** @inheritdoc */
90
    public function overrideSupportedColorModes(Traversable $supportedColorModes): static
91
    {
92
        Asserter::assertColorModes($supportedColorModes);
93
        static::$supportedColorModes = $supportedColorModes;
94
        return $this;
95
    }
96
}
97