Passed
Push — master ( bbf21e...5e1b04 )
by Alec
03:12
created

Terminal::supports256Color()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\ConsoleColour;
4
5
use AlecRabbit\ConsoleColour\Core\AbstractColorSupportingTerminal;
6
use AlecRabbit\ConsoleColour\Core\Contracts\TerminalInterface;
7
use phpDocumentor\Reflection\Types\Boolean;
8
9
/**
10
 * Class Terminal
11
 * @author AlecRabbit
12
 */
13
class Terminal extends AbstractColorSupportingTerminal implements TerminalInterface
14
{
15
16
    /** {@inheritdoc} */
17 2
    public function width(bool $recheck = false): int
18
    {
19 2
        if (null !== static::$width && true !== $recheck) {
20 2
            return static::$width;
21
        }
22
        return
23 2
            static::$width = $this->getWidth();
24
    }
25
26
27
    /** {@inheritdoc} */
28 2
    public function height(bool $recheck = false): int
29
    {
30 2
        if (null !== static::$height && true !== $recheck) {
31 2
            return static::$height;
32
        }
33
        return
34 2
            static::$height = $this->getHeight();
35
    }
36
37
    /** {@inheritdoc} */
38 8
    public function supports256Color(bool $recheck = false): bool
39
    {
40 8
        if (null !== static::$supports256Color && true !== $recheck) {
41 8
            return static::$supports256Color;
42
        }
43
        return
44 1
            static::$supports256Color = $this->has256ColorSupport();
45
    }
46
47
    /** {@inheritdoc} */
48 8
    public function supportsColor(bool $recheck = false): bool
49
    {
50 8
        if (null !== static::$supportsColor && true !== $recheck) {
51 8
            return static::$supportsColor;
52
        }
53
        return
54 1
            static::$supportsColor = $this->hasColorSupport();
55
    }
56
57
    /** {@inheritdoc} */
58
    public function setTitle(string $title): string
59
    {
60
        if ($this->isXterm()) {
61
            return "\033]0;{$title}\007";
62
        }
63
        return (string)null;
64
    }
65
}
66