Passed
Push — master ( 220960...7c8c93 )
by Alec
02:41
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\Control;
4
5
use AlecRabbit\Control\Core\AbstractColorSupportingTerminal;
6
use AlecRabbit\Control\Core\Contracts\TerminalInterface;
7
8
/**
9
 * Class Terminal
10
 * @author AlecRabbit
11
 */
12
class Terminal extends AbstractColorSupportingTerminal implements TerminalInterface
13
{
14
15
    /** {@inheritdoc} */
16 2
    public function width(bool $recheck = false): int
17
    {
18 2
        if (null !== static::$width && true !== $recheck) {
19 2
            return static::$width;
20
        }
21
        return
22 2
            static::$width = $this->getWidth();
23
    }
24
25
26
    /** {@inheritdoc} */
27 2
    public function height(bool $recheck = false): int
28
    {
29 2
        if (null !== static::$height && true !== $recheck) {
30 2
            return static::$height;
31
        }
32
        return
33 2
            static::$height = $this->getHeight();
34
    }
35
36
    /** {@inheritdoc} */
37 8
    public function supports256Color(bool $recheck = false): bool
38
    {
39 8
        if (null !== static::$supports256Color && true !== $recheck) {
40 8
            return static::$supports256Color;
41
        }
42
        return
43 1
            static::$supports256Color = $this->has256ColorSupport();
44
    }
45
46
    /** {@inheritdoc} */
47 8
    public function supportsColor(bool $recheck = false): bool
48
    {
49 8
        if (null !== static::$supportsColor && true !== $recheck) {
50 8
            return static::$supportsColor;
51
        }
52
        return
53 1
            static::$supportsColor = $this->hasColorSupport();
54
    }
55
56
    /** {@inheritdoc} */
57 1
    public function setTitle(string $title): string
58
    {
59 1
        if ($this->isXterm()) {
60 1
            return "\033]0;{$title}\007";
61
        }
62
        // @codeCoverageIgnoreStart
63
        return (string)null;
64
        // @codeCoverageIgnoreEnd
65
    }
66
}
67