1 | <?php |
||
27 | final class Style |
||
28 | { |
||
29 | /** |
||
30 | * @var ConsoleOutput |
||
31 | */ |
||
32 | private $output; |
||
33 | |||
34 | /** |
||
35 | * @var ConsoleSectionOutput |
||
36 | */ |
||
37 | private $footer; |
||
38 | |||
39 | /** |
||
40 | * Style constructor. |
||
41 | * |
||
42 | * @param ConsoleOutput $output |
||
43 | */ |
||
44 | 3 | public function __construct(ConsoleOutput $output) |
|
50 | |||
51 | /** |
||
52 | * Prints the content similar too:. |
||
53 | * |
||
54 | * ``` |
||
55 | * PASS Unit\ExampleTest |
||
56 | * ✓ basic test |
||
57 | * ``` |
||
58 | * |
||
59 | * @param State $state |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | public function writeCurrentRecap(State $state): void |
||
87 | |||
88 | /** |
||
89 | * Prints the content similar too on the footer. Where |
||
90 | * we are updating the current test. |
||
91 | * |
||
92 | * ``` |
||
93 | * Runs Unit\ExampleTest |
||
94 | * • basic test |
||
95 | * ``` |
||
96 | * |
||
97 | * @param State $state |
||
98 | * @param TestCase|null $testCase |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | public function updateFooter(State $state, TestCase $testCase = null): void |
||
146 | |||
147 | /** |
||
148 | * Writes the final recap. |
||
149 | * |
||
150 | * @param Timer $timer |
||
151 | */ |
||
152 | public function writeRecap(Timer $timer): void |
||
162 | |||
163 | /** |
||
164 | * Displays the error using Collision's writer |
||
165 | * and terminates with exit code === 1. |
||
166 | * |
||
167 | * @param Throwable $throwable |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | public function writeError(State $state, Throwable $throwable) |
||
205 | |||
206 | /** |
||
207 | * Returns the title contents. |
||
208 | * |
||
209 | * @param string $fg |
||
210 | * @param string $bg |
||
211 | * @param string $title |
||
212 | * @param string $testCaseClass |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | private function titleLineFrom(string $fg, string $bg, string $title, string $testCaseClass): string |
||
234 | |||
235 | /** |
||
236 | * Returns the test contents. |
||
237 | * |
||
238 | * @param string $fg |
||
239 | * @param string $icon |
||
240 | * @param string $description |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | private function testLineFrom(string $fg, string $icon, string $description, string $warning = null): string |
||
261 | } |
||
262 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.