Passed
Push — main ( 545ade...3cfdef )
by Andrey
79:39 queued 77:29
created

Message::getPackage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Concerns\Contains;
6
use Helldar\LaravelLangPublisher\Concerns\Keyable;
7
use Helldar\LaravelLangPublisher\Concerns\Logger;
8
use Helldar\LaravelLangPublisher\Constants\Status;
9
use Helldar\Support\Facades\Helpers\Str;
10
11
final class Message
12
{
13
    use Contains;
14
    use Keyable;
15
    use Logger;
0 ignored issues
show
Bug introduced by
The trait Helldar\LaravelLangPublisher\Concerns\Logger requires the property $output which is not provided by Helldar\LaravelLangPublisher\Support\Message.
Loading history...
16
17
    protected $styles = [
18
        Status::COPIED  => 'fg=green',
19
        Status::RESET   => 'fg=magenta',
20
        Status::SKIPPED => 'fg=default',
21
        Status::DELETED => 'fg=red',
22
    ];
23
24
    protected $locales_length = 0;
25
26
    protected $files_length = 0;
27
28
    protected $package;
29
30
    protected $locale;
31
32
    protected $filename;
33
34
    protected $status;
35
36 12
    public function same(): self
37
    {
38 12
        return $this;
39
    }
40
41 12
    public function package(?string $package): self
42
    {
43 12
        $this->package = $package;
44
45 12
        return $this;
46
    }
47
48 12
    public function length(int $locales, int $files): self
49
    {
50 12
        $this->locales_length = abs($locales) + 3;
51 12
        $this->files_length   = abs($files) + 4;
52
53 12
        return $this;
54
    }
55
56 12
    public function locale(string $locale): self
57
    {
58 12
        $this->locale = $locale;
59
60 12
        return $this;
61
    }
62
63 12
    public function filename(string $filename): self
64
    {
65 12
        $this->filename = $this->key($filename);
66
67 12
        return $this;
68
    }
69
70 12
    public function status(string $status): self
71
    {
72 12
        $this->status = $status;
73
74 12
        return $this;
75
    }
76
77 12
    public function get(): string
78
    {
79 12
        return $this->getPackage() . $this->getLocale() . $this->getFilename() . $this->getStatus();
80
    }
81
82 12
    protected function pad(string $value, int $length): string
83
    {
84 12
        return str_pad($value, $length);
85
    }
86
87 12
    protected function getPackage(): string
88
    {
89 12
        if (empty($this->package)) {
90 4
            return '';
91
        }
92
93 11
        $length = Str::length($this->package);
94
95 11
        $value = $this->pad($this->package, $length + 1);
96
97 11
        return $this->format($value, 'fg=#a6a6a6');
98
    }
99
100 12
    protected function getLocale(): string
101
    {
102 12
        $value = $this->pad("[$this->locale]", $this->locales_length);
103
104 12
        return $this->format($value, 'comment');
105
    }
106
107 12
    protected function getFilename(): string
108
    {
109 12
        $value = $this->pad($this->filename . '...', $this->files_length);
110
111 12
        return $this->format($value);
112
    }
113
114 12
    protected function getStatus(): string
115
    {
116 12
        $style = $this->styles[$this->status];
117
118 12
        return $this->format($this->status, $style);
119
    }
120
121 12
    protected function format(string $value, string $style = null): string
122
    {
123 12
        return $style ? "<$style>$value</>" : $value;
124
    }
125
}
126