72% of 932OPs |
82% of 154Lines |
66% of 112Branches |
5% of 305Paths |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\report\fields\runner\errors; |
4 |
|
5 |
use |
6 |
mageekguy\atoum, |
7 |
mageekguy\atoum\locale, |
8 |
mageekguy\atoum\report, |
9 |
mageekguy\atoum\cli\prompt, |
10 |
mageekguy\atoum\cli\colorizer |
11 |
; |
12 |
|
13 |
class cli extends report\fields\runner\errors |
14 |
{ |
15 |
protected $titlePrompt = null; |
16 |
protected $titleColorizer = null; |
17 |
protected $methodPrompt = null; |
18 |
protected $methodColorizer = null; |
19 |
protected $errorPrompt = null; |
20 |
protected $errorColorizer = null; |
21 |
|
22 |
public function __construct()100% |
23 |
{ |
24 |
parent::__construct(); |
25 |
|
26 |
$this |
27 |
->setTitlePrompt() |
28 |
->setTitleColorizer() |
29 |
->setMethodPrompt() |
30 |
->setMethodColorizer() |
31 |
->setErrorPrompt() |
32 |
->setErrorColorizer() |
33 |
; |
34 |
} |
35 |
|
36 |
public function __toString()78% |
37 |
{ |
38 |
$string = ''; |
39 |
|
40 |
if ($this->runner !== null) |
41 |
{ |
42 |
$errors = $this->runner->getScore()->getErrors(); |
43 |
|
44 |
$sizeOfErrors = sizeof($errors); |
45 |
|
46 |
if ($sizeOfErrors > 0) |
47 |
{ |
48 |
$string .= |
49 |
$this->titlePrompt . |
50 |
sprintf( |
51 |
$this->locale->_('%s:'), |
52 |
$this->titleColorizer->colorize(sprintf($this->locale->__('There is %d error', 'There are %d errors', $sizeOfErrors), $sizeOfErrors)) |
53 |
) . |
54 |
PHP_EOL |
55 |
; |
56 |
|
57 |
$class = null; |
58 |
$method = null; |
59 |
|
60 |
foreach ($errors as $error) |
61 |
{ |
62 |
if ($error['class'] !== $class || $error['method'] !== $method) |
63 |
{ |
64 |
$string .= |
65 |
$this->methodPrompt . |
66 |
sprintf( |
67 |
$this->locale->_('%s:'), |
68 |
$this->methodColorizer->colorize($error['class'] . '::' . $error['method'] . '()') |
69 |
) . |
70 |
PHP_EOL |
71 |
; |
72 |
|
73 |
$class = $error['class']; |
74 |
$method = $error['method']; |
75 |
} |
76 |
|
77 |
$string .= $this->errorPrompt; |
78 |
|
79 |
$type = static::getType($error['type']); |
80 |
|
81 |
if ($error['case'] === null) |
82 |
{ |
83 |
switch (true) |
84 |
{ |
85 |
case $error['file'] === null: |
86 |
switch (true) |
87 |
{ |
88 |
case $error['errorFile'] === null: |
89 |
$errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by unknown file'), $type); |
90 |
break; |
91 |
|
92 |
case $error['errorLine'] === null: |
93 |
$errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s'), $type, $error['errorFile']); |
94 |
break; |
95 |
|
96 |
case $error['errorLine'] !== null: |
97 |
$errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s on line %d'), $type, $error['errorFile'], $error['errorLine']); |
98 |
break; |
99 |
} |
100 |
break; |
101 |
|
102 |
case $error['line'] === null: |
103 |
switch (true) |
104 |
{ |
105 |
case $error['errorFile'] === null: |
106 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by unknown file'), $type, $error['file']); |
107 |
break; |
108 |
|
109 |
case $error['errorLine'] === null: |
110 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s'), $type, $error['file'], $error['errorFile']); |
111 |
break; |
112 |
|
113 |
case $error['errorLine'] !== null: |
114 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s on line %d'), $type, $error['file'], $error['errorFile'], $error['errorLine']); |
115 |
break; |
116 |
} |
117 |
break; |
118 |
|
119 |
default: |
120 |
switch (true) |
121 |
{ |
122 |
case $error['errorFile'] === null: |
123 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by unknown file'), $type, $error['file'], $error['line']); |
124 |
break; |
125 |
|
126 |
case $error['errorLine'] === null: |
127 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s'), $type, $error['file'], $error['line'], $error['errorFile']); |
128 |
break; |
129 |
|
130 |
case $error['errorLine'] !== null: |
131 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s on line %d'), $type, $error['file'], $error['line'], $error['errorFile'], $error['errorLine']); |
132 |
break; |
133 |
} |
134 |
break; |
135 |
} |
136 |
} |
137 |
else |
138 |
{ |
139 |
switch (true) |
140 |
{ |
141 |
case $error['file'] === null: |
142 |
switch (true) |
143 |
{ |
144 |
case $error['errorFile'] === null: |
145 |
$errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line in case \'%s\', generated by unknown file'), $type, $error['case']); |
146 |
break; |
147 |
|
148 |
case $error['errorLine'] === null: |
149 |
$errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s in case \'%s\''), $type, $error['errorFile'], $error['case']); |
150 |
break; |
151 | |
152 |
case $error['errorLine'] !== null: |
153 |
$errorMessage = sprintf($this->locale->_('Error %s in unknown file on unknown line, generated by file %s on line %d in case \'%s\''), $type, $error['errorFile'], $error['errorLine'], $error['case']); |
154 |
break; |
155 |
} |
156 |
break; |
157 |
|
158 |
case $error['line'] === null: |
159 |
switch (true) |
160 |
{ |
161 |
case $error['errorFile'] === null: |
162 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by unknown file in case \'%s\''), $type, $error['file'], $error['case']); |
163 |
break; |
164 |
|
165 |
case $error['errorLine'] === null: |
166 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s in case \'%s\''), $type, $error['file'], $error['errorFile'], $error['case']); |
167 |
break; |
168 |
|
169 |
case $error['errorLine'] !== null: |
170 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on unknown line, generated by file %s on line %d in case \'%s\''), $type, $error['file'], $error['errorFile'], $error['errorLine'], $error['case']); |
171 |
break; |
172 |
} |
173 |
break; |
174 |
|
175 |
default: |
176 |
switch (true) |
177 |
{ |
178 |
case $error['errorFile'] === null: |
179 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by unknown file in case \'%s\''), $type, $error['file'], $error['line'], $error['case']); |
180 |
break; |
181 |
|
182 |
case $error['errorLine'] === null: |
183 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s in case \'%s\''), $type, $error['file'], $error['line'], $error['errorFile'], $error['case']); |
184 |
break; |
185 |
|
186 |
case $error['errorLine'] !== null: |
187 |
$errorMessage = sprintf($this->locale->_('Error %s in %s on line %d, generated by file %s on line %d in case \'%s\''), $type, $error['file'], $error['line'], $error['errorFile'], $error['errorLine'], $error['case']); |
188 |
break; |
189 |
} |
190 |
break; |
191 |
} |
192 |
} |
193 |
|
194 |
$string .= sprintf( |
195 |
$this->locale->_('%s:'), |
196 |
$this->errorColorizer->colorize(($errorMessage)) |
197 |
) . |
198 |
PHP_EOL |
199 |
; |
200 |
|
201 |
foreach (explode(PHP_EOL, $error['message']) as $line) |
202 |
{ |
203 |
$string .= $line . PHP_EOL; |
204 |
} |
205 |
} |
206 |
} |
207 |
} |
208 |
|
209 |
return $string; |
210 |
} |
211 |
|
212 |
public function setTitlePrompt(prompt $prompt = null)100% |
213 |
{ |
214 |
$this->titlePrompt = $prompt ?: new prompt(); |
215 |
|
216 |
return $this; |
217 |
} |
218 |
|
219 |
public function getTitlePrompt()100% |
220 |
{ |
221 |
return $this->titlePrompt; |
222 |
} |
223 |
|
224 |
public function setTitleColorizer(colorizer $colorizer = null)100% |
225 |
{ |
226 |
$this->titleColorizer = $colorizer ?: new colorizer(); |
227 |
|
228 |
return $this; |
229 |
} |
230 |
|
231 |
public function getTitleColorizer()100% |
232 |
{ |
233 |
return $this->titleColorizer; |
234 |
} |
235 |
|
236 |
public function setMethodPrompt(prompt $prompt = null)100% |
237 |
{ |
238 |
$this->methodPrompt = $prompt ?: new prompt(); |
239 |
|
240 |
return $this; |
241 |
} |
242 |
|
243 |
public function getMethodPrompt()100% |
244 |
{ |
245 |
return $this->methodPrompt; |
246 |
} |
247 |
|
248 |
public function setMethodColorizer(colorizer $colorizer = null)100% |
249 |
{ |
250 |
$this->methodColorizer = $colorizer ?: new colorizer(); |
251 |
|
252 |
return $this; |
253 |
} |
254 |
|
255 |
public function getMethodColorizer()100% |
256 |
{ |
257 |
return $this->methodColorizer; |
258 |
} |
259 |
|
260 |
public function setErrorPrompt(prompt $prompt = null)100% |
261 |
{ |
262 |
$this->errorPrompt = $prompt ?: new prompt(); |
263 |
|
264 |
return $this; |
265 |
} |
266 |
|
267 |
public function getErrorPrompt()100% |
268 |
{ |
269 |
return $this->errorPrompt; |
270 |
} |
271 |
|
272 |
public function setErrorColorizer(colorizer $colorizer = null)100% |
273 |
{ |
274 |
$this->errorColorizer = $colorizer ?: new colorizer(); |
275 |
|
276 |
return $this; |
277 |
} |
278 |
|
279 |
public function getErrorColorizer()100% |
280 |
{ |
281 |
return $this->errorColorizer; |
282 |
} |
283 |
} |