Completed
Push — develop ( fe1195...b733eb )
by Alec
05:48
created

Theme::info()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 24.12.18
5
 * Time: 15:17
6
 */
7
declare(strict_types=1);
8
9
namespace AlecRabbit\Tools\Internal;
10
11
use AlecRabbit\ConsoleColour;
12
13
class Theme extends ConsoleColour implements ThemesInterface
14
{
15
    /** @var bool */
16
    private $do;
17
18 1
    public function __construct(bool $color = false)
19
    {
20 1
        $this->do = $color;
21 1
        parent::__construct();
22 1
        $this->setDefaultThemes();
23 1
    }
24
25 1
    protected function setDefaultThemes(): void
26
    {
27 1
        $this->addTheme(static::DARK, 'dark');
28 1
        $this->addTheme(static::COMMENT, 'yellow');
29 1
        $this->addTheme(static::INFO, 'green');
30 1
        $this->addTheme(static::RED, 'red');
31 1
    }
32
33
    /**
34
     * @param string $text
35
     * @return string
36
     * @throws \Throwable
37
     */
38 2
    public function comment(string $text): string
39
    {
40
        return
41 2
            $this->apply(static::COMMENT, $text);
42
    }
43
44
    /**
45
     * @param string $text
46
     * @return string
47
     * @throws \Throwable
48
     */
49 1
    public function yellow(string $text): string
50
    {
51
        return
52 1
            $this->apply(static::COMMENT, $text);
53
    }
54
55
    /**
56
     * @param string $text
57
     * @return string
58
     * @throws \Throwable
59
     */
60 2
    public function apply($style, $text): string
61
    {
62 2
        return $this->do ? parent::apply($style, $text) : (string)$text;
63
    }
64
65
    /**
66
     * @param string $text
67
     * @return string
68
     * @throws \Throwable
69
     */
70
    public function red(string $text): string
71
    {
72
        return
73
            $this->apply(static::RED, $text);
74
    }
75
76
    /**
77
     * @param string $text
78
     * @return string
79
     * @throws \Throwable
80
     */
81 1
    public function info(string $text): string
82
    {
83
        return
84 1
            $this->apply(static::INFO, $text);
85
    }
86
87
    /**
88
     * @param string $text
89
     * @return string
90
     * @throws \Throwable
91
     */
92 1
    public function green(string $text): string
93
    {
94
        return
95 1
            $this->apply(static::INFO, $text);
96
    }
97
98
    /**
99
     * @param string $text
100
     * @return string
101
     * @throws \Throwable
102
     */
103 2
    public function dark(string $text): string
104
    {
105
        return
106 2
            $this->apply(static::DARK, $text);
107
    }
108
}
109