Passed
Push — master ( 6196c7...258f0b )
by Alec
07:21
created

TerminalStatic   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 93.55%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 89
ccs 29
cts 31
cp 0.9355
rs 10
wmc 21

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setTitle() 0 7 2
A supportsTrueColor() 0 7 3
A supports256Color() 0 7 3
A height() 0 7 3
A colorSupport() 0 23 4
A supportsColor() 0 7 3
A width() 0 7 3
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Cli\Tools\Core;
4
5
use AlecRabbit\Cli\Tools\Core\Contracts\TerminalStaticInterface;
6
use AlecRabbit\Cli\Tools\Stream;
7
use const AlecRabbit\COLOR256_TERMINAL;
8
use const AlecRabbit\COLOR_TERMINAL;
9
use const AlecRabbit\NO_COLOR_TERMINAL;
10
use const AlecRabbit\TRUECOLOR_TERMINAL;
11
12
/**
13
 * Class Terminal
14
 * @author AlecRabbit
15
 */
16
class TerminalStatic extends AbstractColorSupportingTerminal implements TerminalStaticInterface
17
{
18
19
    /** {@inheritdoc} */
20 1
    public static function setTitle(string $title): string
21
    {
22 1
        if (static::isXterm()) {
23 1
            return "\033]0;{$title}\007";
24
        }
25
        // @codeCoverageIgnoreStart
26
        return (string)null;
27
        // @codeCoverageIgnoreEnd
28
    }
29
30
    /** {@inheritdoc} */
31 6
    public static function width(bool $recheck = false): int
32
    {
33 6
        if (null !== static::$width && true !== $recheck) {
34 6
            return static::$width;
35
        }
36
        return
37 2
            static::$width = static::getWidth();
38
    }
39
40
    /** {@inheritdoc} */
41 6
    public static function height(bool $recheck = false): int
42
    {
43 6
        if (null !== static::$height && true !== $recheck) {
44 6
            return static::$height;
45
        }
46
        return
47 2
            static::$height = static::getHeight();
48
    }
49
50
    /** {@inheritdoc} */
51 4
    public static function colorSupport($stream = null): int
52
    {
53 4
        $colorSupport = NO_COLOR_TERMINAL;
54 4
        if (static::supportsColor(true, $stream)) {
55
            return
56 4
                static::supportsTrueColor() ?
57
                    TRUECOLOR_TERMINAL:
58
                    (
59 4
                    static::supports256Color() ?
60
                        COLOR256_TERMINAL :
61 4
                        COLOR_TERMINAL
62
                    );
63
//            return
64
//                static::supports256Color() ?
65
//                    COLOR256_TERMINAL:
66
//                    (
67
//                    static::supportsTrueColor() ?
68
//                        TRUECOLOR_TERMINAL :
69
//                        COLOR_TERMINAL
70
//                    );
71
        }
72
        // @codeCoverageIgnoreStart
73
        return $colorSupport;
74
        // @codeCoverageIgnoreEnd
75
    }
76
77
    /** {@inheritdoc} */
78 5
    public static function supportsColor(bool $recheck = false, $stream = null): bool
79
    {
80 5
        if (null !== static::$supportsColor && false === $recheck) {
81 2
            return static::$supportsColor;
82
        }
83
        return
84 5
            static::$supportsColor = Stream::hasColorSupport($stream);
85
    }
86
87
    /** {@inheritdoc} */
88 5
    public static function supports256Color(bool $recheck = false): bool
89
    {
90 5
        if (null !== static::$supports256Color && true !== $recheck) {
91 4
            return static::$supports256Color;
92
        }
93
        return
94 1
            static::$supports256Color = static::has256ColorSupport();
95
    }
96
97
    /** {@inheritdoc} */
98 4
    public static function supportsTrueColor(bool $recheck = false): bool
99
    {
100 4
        if (null !== static::$supportsTrueColor && true !== $recheck) {
101 3
            return static::$supportsTrueColor;
102
        }
103
        return
104 1
            static::$supportsTrueColor = static::hasTrueColorSupport();
105
    }
106
}
107