1 | <?php |
||
2 | |||
3 | namespace Helldar\LaravelLangPublisher\Support; |
||
4 | |||
5 | use Helldar\LaravelLangPublisher\Facades\Arr; |
||
0 ignored issues
–
show
|
|||
6 | use Illuminate\Console\Command; |
||
7 | use Illuminate\Support\Str; |
||
8 | |||
9 | final class Result |
||
10 | { |
||
11 | /** @var \Illuminate\Console\Command */ |
||
12 | protected $output; |
||
13 | |||
14 | protected $items = []; |
||
15 | |||
16 | protected $message = 'No Data'; |
||
17 | |||
18 | 36 | public function setOutput(Command $output): self |
|
19 | { |
||
20 | 36 | $this->output = $output; |
|
21 | |||
22 | 36 | return $this; |
|
23 | } |
||
24 | |||
25 | public function setMessage(string $no_data): self |
||
26 | { |
||
27 | $this->message = $no_data; |
||
28 | |||
29 | return $this; |
||
30 | } |
||
31 | |||
32 | public function show() |
||
33 | { |
||
34 | empty($this->items) ? $this->warn() : $this->table(); |
||
35 | } |
||
36 | |||
37 | public function merge(array $items): void |
||
38 | { |
||
39 | $this->items = array_merge($this->items, $items); |
||
40 | } |
||
41 | |||
42 | protected function warn(): void |
||
43 | { |
||
44 | $this->output->warn($this->message); |
||
45 | } |
||
46 | |||
47 | protected function table(): void |
||
48 | { |
||
49 | $this->output->table($this->headers(), $this->items()); |
||
50 | } |
||
51 | |||
52 | protected function headers(): array |
||
53 | { |
||
54 | $item = Arr::first($this->items); |
||
55 | $keys = Arr::keys($item); |
||
56 | |||
57 | return Arr::transform($keys, function ($value) { |
||
58 | return Str::title($value); |
||
59 | }); |
||
60 | } |
||
61 | |||
62 | protected function items(): array |
||
63 | { |
||
64 | return $this->items; |
||
65 | } |
||
66 | } |
||
67 |
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: