Passed
Push — 9.x ( 166f03...f9e7ac )
by Andrey
196:56 queued 181:57
created

Message   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 82
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 3 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
9
final class Message
10
{
11
    use Contains;
12
    use Keyable;
13
    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...
14
15
    protected $locales_length = 0;
16
17
    protected $files_length = 0;
18
19
    protected $locale;
20
21
    protected $filename;
22
23
    protected $status;
24
25
    public function same(): self
26
    {
27
        return $this;
28
    }
29
30
    public function length(int $locales, int $files): self
31
    {
32
        $this->locales_length = abs($locales) + 3;
33
        $this->files_length   = abs($files) + 4;
34
35
        return $this;
36
    }
37
38
    public function locale(string $locale): self
39
    {
40
        $this->locale = $locale;
41
42
        return $this;
43
    }
44
45
    public function filename(string $filename): self
46
    {
47
        $this->filename = $this->key($filename);
48
49
        return $this;
50
    }
51
52
    public function status(string $status): self
53
    {
54
        $this->status = $status;
55
56
        return $this;
57
    }
58
59
    public function get(): string
60
    {
61
        return $this->getLocale() . $this->getFilename() . $this->getStatus();
62
    }
63
64
    protected function pad(string $value, int $length): string
65
    {
66
        return str_pad($value, $length);
67
    }
68
69
    protected function getLocale(): string
70
    {
71
        $value = $this->pad("[$this->locale]", $this->locales_length);
72
73
        return $this->format($value, 'comment');
74
    }
75
76
    protected function getFilename(): string
77
    {
78
        $value = $this->pad($this->filename . '...', $this->files_length);
79
80
        return $this->format($value);
81
    }
82
83
    protected function getStatus(): string
84
    {
85
        return $this->format($this->status, 'info');
86
    }
87
88
    protected function format(string $value, string $style = null): string
89
    {
90
        return $style ? "<$style>$value</$style>" : $value;
91
    }
92
}
93