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

ATerminalSettings.php$0 ➔ getStyleMode()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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