Passed
Pull Request — main (#84)
by Andrey
196:26 queued 181:26
created

Message::status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
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
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
    public function same(): self
34
    {
35
        return $this;
36
    }
37
38
    public function length(int $locales, int $files): self
39
    {
40
        $this->locales_length = abs($locales) + 3;
41
        $this->files_length   = abs($files) + 4;
42
43
        return $this;
44
    }
45
46
    public function locale(string $locale): self
47
    {
48
        $this->locale = $locale;
49
50
        return $this;
51
    }
52
53
    public function filename(string $filename): self
54
    {
55
        $this->filename = $this->key($filename);
56
57
        return $this;
58
    }
59
60
    public function status(string $status): self
61
    {
62
        $this->status = $status;
63
64
        return $this;
65
    }
66
67
    public function get(): string
68
    {
69
        return $this->getLocale() . $this->getFilename() . $this->getStatus();
70
    }
71
72
    protected function pad(string $value, int $length): string
73
    {
74
        return str_pad($value, $length);
75
    }
76
77
    protected function getLocale(): string
78
    {
79
        $value = $this->pad("[$this->locale]", $this->locales_length);
80
81
        return $this->format($value, 'comment');
82
    }
83
84
    protected function getFilename(): string
85
    {
86
        $value = $this->pad($this->filename . '...', $this->files_length);
87
88
        return $this->format($value);
89
    }
90
91
    protected function getStatus(): string
92
    {
93
        $style = $this->styles[$this->status];
94
95
        return $this->format($this->status, $style);
96
    }
97
98
    protected function format(string $value, string $style = null): string
99
    {
100
        return $style ? "<$style>$value</>" : $value;
101
    }
102
}
103