1 | <?php |
||
5 | class Colorizer implements ColorizerInterface |
||
6 | { |
||
7 | |||
8 | public const FOREGROUND_BLACK = '0;30'; |
||
9 | public const FOREGROUND_RED = '0;31'; |
||
10 | public const FOREGROUND_GREEN = '0;32'; |
||
11 | public const FOREGROUND_BROWN = '0;33'; |
||
12 | public const FOREGROUND_BLUE = '0;34'; |
||
13 | public const FOREGROUND_MAGENTA = '0;35'; |
||
14 | public const FOREGROUND_CYAN = '0;36'; |
||
15 | public const FOREGROUND_LIGHTGREY = '0;37'; |
||
16 | public const FOREGROUND_DARKGREY = '1;30'; |
||
17 | public const FOREGROUND_LIGHTRED = '1;31'; |
||
18 | public const FOREGROUND_LIGHTGREEN = '1;32'; |
||
19 | public const FOREGROUND_YELLOW = '1;33'; |
||
20 | public const FOREGROUND_LIGHTBLUE = '1;34'; |
||
21 | public const FOREGROUND_PURPLE = '1;35'; |
||
22 | public const FOREGROUND_LIGHTCYAN = '1;36'; |
||
23 | public const FOREGROUND_WHITE = '1;37'; |
||
24 | |||
25 | public const BACKGROUND_BLACK = 40; |
||
26 | public const BACKGROUND_RED = 41; |
||
27 | public const BACKGROUND_GREEN = 42; |
||
28 | public const BACKGROUND_YELLOW = 43; |
||
29 | public const BACKGROUND_BLUE = 44; |
||
30 | public const BACKGROUND_MAGENTA = 45; |
||
31 | public const BACKGROUND_CYAN = 46; |
||
32 | public const BACKGROUND_LIGHTGREY = 47; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $foregroundColor; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $foregroundText; |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $backgroundColor; |
||
42 | |||
43 | /** @var string */ |
||
44 | protected $backgroundText; |
||
45 | |||
46 | /** @var array */ |
||
47 | public static $foregroundTexts = [ |
||
48 | '0;30' => 'black', |
||
49 | '0;31' => 'red', |
||
50 | '0;32' => 'green', |
||
51 | '0;33' => 'brown', |
||
52 | '0;34' => 'blue', |
||
53 | '0;35' => 'magenta', |
||
54 | '0;36' => 'cyan', |
||
55 | '0;37' => 'lightGrey', |
||
56 | '1;30' => 'darkGrey', |
||
57 | '1;31' => 'lightRed', |
||
58 | '1;32' => 'lightGreen', |
||
59 | '1;33' => 'yellow', |
||
60 | '1;34' => 'lightBlue', |
||
61 | '1;35' => 'lightPurple', |
||
62 | '1;36' => 'lightCyan', |
||
63 | '1;37' => 'white', |
||
64 | ]; |
||
65 | |||
66 | /** @var array */ |
||
67 | public static $backgroundTexts = [ |
||
68 | 40 => 'black', |
||
69 | 41 => 'red', |
||
70 | 42 => 'green', |
||
71 | 43 => 'yellow', |
||
72 | 44 => 'blue', |
||
73 | 45 => 'magenta', |
||
74 | 46 => 'cyan', |
||
75 | 47 => 'lightgrey' |
||
76 | ]; |
||
77 | |||
78 | /** |
||
79 | * @inheritDoc |
||
80 | */ |
||
81 | public function color( |
||
94 | |||
95 | /** |
||
96 | * @param string $foregroundCode |
||
97 | * |
||
98 | * @param null $text |
||
99 | * |
||
100 | * @return bool|Colorizer |
||
101 | */ |
||
102 | public function setForegroundCode(string $foregroundCode, $text = null) |
||
121 | |||
122 | /** |
||
123 | * @param string|int $backgroundColor |
||
124 | * @param null $text |
||
125 | * |
||
126 | * @return bool|Colorizer |
||
127 | */ |
||
128 | public function setBackgroundColor($backgroundColor, $text = null) |
||
150 | |||
151 | /** |
||
152 | * @return array |
||
153 | */ |
||
154 | public function getForegroundColors(): array |
||
158 | |||
159 | /** |
||
160 | * @return array |
||
161 | */ |
||
162 | public function getBackgroundColors(): array |
||
166 | |||
167 | /** |
||
168 | * @param string $sentence |
||
169 | * @param array $arguments |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | private function doColorize(string $sentence, array $arguments): string |
||
193 | |||
194 | /** |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getForegroundText(): string |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getBackgroundText(): string |
||
209 | } |
||
210 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.