Passed
Push — master ( 9e6f1e...220960 )
by Alec
03:13
created

Terminal::setTitle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 2.0625
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
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
        return (string)null;
63
    }
64
}
65