Total Complexity | 9 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Coverage | 12% |
Changes | 0 |
1 | <?php |
||
12 | final class Result implements ResultContract |
||
13 | { |
||
14 | /** @var \Illuminate\Console\Command */ |
||
15 | protected $output; |
||
16 | |||
17 | protected $items = []; |
||
18 | |||
19 | protected $message = 'No Data'; |
||
20 | |||
21 | 18 | public function setOutput(Command $output): self |
|
22 | { |
||
23 | 18 | $this->output = $output; |
|
24 | |||
25 | 18 | return $this; |
|
26 | } |
||
27 | |||
28 | public function setMessage(string $no_data): self |
||
29 | { |
||
30 | $this->message = $no_data; |
||
31 | |||
32 | return $this; |
||
33 | } |
||
34 | |||
35 | public function show() |
||
36 | { |
||
37 | empty($this->items) ? $this->warn() : $this->table(); |
||
38 | } |
||
39 | |||
40 | public function merge(array $items): void |
||
41 | { |
||
42 | $this->items = array_merge($this->items, $items); |
||
43 | } |
||
44 | |||
45 | protected function warn(): void |
||
46 | { |
||
47 | $this->output->warn($this->message); |
||
48 | } |
||
49 | |||
50 | protected function table(): void |
||
51 | { |
||
52 | $this->output->table($this->headers(), $this->items()); |
||
53 | } |
||
54 | |||
55 | protected function headers(): array |
||
56 | { |
||
57 | $item = Arr::first($this->items); |
||
58 | $keys = Arr::keys($item); |
||
59 | |||
60 | return Arr::transform($keys, function ($value) { |
||
61 | return Str::title($value); |
||
62 | }); |
||
63 | } |
||
64 | |||
65 | protected function items(): array |
||
68 | } |
||
69 | } |
||
70 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: