Passed
Push — main ( 55f929...127e84 )
by Andrey
161:41 queued 158:10
created

Message   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 91
ccs 30
cts 30
cp 1
rs 10
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilename() 0 5 1
A length() 0 6 1
A pad() 0 3 1
A status() 0 5 1
A getLocale() 0 5 1
A getStatus() 0 5 1
A same() 0 3 1
A locale() 0 5 1
A filename() 0 5 1
A format() 0 3 2
A get() 0 3 1
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
10
final class Message
11
{
12
    use Contains;
13
    use Keyable;
14
    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...
15
16
    protected $styles = [
17
        Status::COPIED  => 'fg=green',
18
        Status::RESET   => 'fg=magenta',
19
        Status::SKIPPED => 'fg=default',
20
        Status::DELETED => 'fg=red',
21
    ];
22
23
    protected $locales_length = 0;
24
25
    protected $files_length = 0;
26
27
    protected $locale;
28
29
    protected $filename;
30
31
    protected $status;
32
33 12
    public function same(): self
34
    {
35 12
        return $this;
36
    }
37
38 12
    public function length(int $locales, int $files): self
39
    {
40 12
        $this->locales_length = abs($locales) + 3;
41 12
        $this->files_length   = abs($files) + 4;
42
43 12
        return $this;
44
    }
45
46 12
    public function locale(string $locale): self
47
    {
48 12
        $this->locale = $locale;
49
50 12
        return $this;
51
    }
52
53 12
    public function filename(string $filename): self
54
    {
55 12
        $this->filename = $this->key($filename);
56
57 12
        return $this;
58
    }
59
60 12
    public function status(string $status): self
61
    {
62 12
        $this->status = $status;
63
64 12
        return $this;
65
    }
66
67 12
    public function get(): string
68
    {
69 12
        return $this->getLocale() . $this->getFilename() . $this->getStatus();
70
    }
71
72 12
    protected function pad(string $value, int $length): string
73
    {
74 12
        return str_pad($value, $length);
75
    }
76
77 12
    protected function getLocale(): string
78
    {
79 12
        $value = $this->pad("[$this->locale]", $this->locales_length);
80
81 12
        return $this->format($value, 'comment');
82
    }
83
84 12
    protected function getFilename(): string
85
    {
86 12
        $value = $this->pad($this->filename . '...', $this->files_length);
87
88 12
        return $this->format($value);
89
    }
90
91 12
    protected function getStatus(): string
92
    {
93 12
        $style = $this->styles[$this->status];
94
95 12
        return $this->format($this->status, $style);
96
    }
97
98 12
    protected function format(string $value, string $style = null): string
99
    {
100 12
        return $style ? "<$style>$value</>" : $value;
101
    }
102
}
103