Passed
Push — master ( a7279d...feb425 )
by Andrey
11:45
created

Result::setMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Entities;
4
5
use Helldar\LaravelLangPublisher\Contracts\Result as ResultContract;
6
use Helldar\LaravelLangPublisher\Facades\Arr;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Str;
9
10
use function array_merge;
11
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
    public function setOutput(Command $output): self
22
    {
23
        $this->output = $output;
24
25
        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
66
    {
67
        return $this->items;
68
    }
69
}
70