Passed
Push — master ( d4a0a9...a5fa1a )
by Alec
02:38 queued 13s
created

ATerminal   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setWidth() 0 3 1
A hp$0 ➔ getInstance() 0 8 2
A getWidth() 0 3 1
A setColorMode() 0 3 1
A getColorMode() 0 3 1
A __construct() 0 12 3
getInstance() 0 8 ?
1
<?php
2
3
declare(strict_types=1);
0 ignored issues
show
Coding Style introduced by
Header blocks must be separated by a single blank line
Loading history...
4
// 09.03.23
5
namespace AlecRabbit\Spinner\Config\Defaults\A;
6
7
use AlecRabbit\Spinner\Config\Defaults\Contract\ITerminal;
8
use AlecRabbit\Spinner\Core\ColorMode;
9
use AlecRabbit\Spinner\Core\Terminal\Contract\ITerminalProbe;
10
11
abstract class ATerminal implements ITerminal
12
{
13
    private static ?ITerminal $instance = null;
14
    private ColorMode $colorMode;
15
    private int $width;
16
17
    private function __construct(iterable $terminalProbes)
18
    {
19
        /** @var ITerminalProbe $terminalProbe */
20
        foreach ($terminalProbes as $terminalProbe) {
21
            if ($terminalProbe::isSupported()) {
22
                $this->colorMode = $terminalProbe::getColorMode();
23
                $this->width = $terminalProbe::getWidth();
24
                return;
25
            }
26
        }
27
        $this->colorMode = ITerminal::TERMINAL_DEFAULT_COLOR_SUPPORT;
28
        $this->width = ITerminal::TERMINAL_DEFAULT_WIDTH;
29
    }
30
31
    public function getColorMode(): ColorMode
32
    {
33
        return $this->colorMode;
34
    }
35
36
    public function setColorMode(ColorMode $colorMode): void
37
    {
38
        $this->colorMode = $colorMode;
39
    }
40
41
    public function getWidth(): int
42
    {
43
        return $this->width;
44
    }
45
46
    public function setWidth(int $width): void
47
    {
48
        $this->width = $width;
49
    }
50
51
    final public static function getInstance(iterable $terminalProbes): self
52
    {
53
        if (null === self::$instance) {
54
            self::$instance =
55
                new class($terminalProbes) extends ATerminal {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class keyword; 0 found
Loading history...
56
                };
57
        }
58
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance could return the type AlecRabbit\Spinner\Confi...ults\Contract\ITerminal which includes types incompatible with the type-hinted return AlecRabbit\Spinner\Config\Defaults\A\ATerminal. Consider adding an additional type-check to rule them out.
Loading history...
59
    }
60
}