Passed
Pull Request — main (#123)
by Andrey
59:27 queued 44:29
created

Config::locales()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Constants\Config as ConfigNames;
6
use Helldar\LaravelLangPublisher\Constants\Locales as LocalesList;
7
use Helldar\PrettyArray\Contracts\Caseable;
8
use Illuminate\Support\Facades\Config as Illuminate;
9
10
final class Config
11
{
12
    /**
13
     * Getting a list of packages from which to synchronize localization files.
14
     *
15
     * @return array
16
     */
17
    public function packages(): array
18
    {
19
        return $this->getList('packages');
20
    }
21
22
    /**
23 40
     * Getting a list of plugins from which to synchronize localization files.
24
     *
25 40
     * @return array
26
     */
27 40
    public function plugins(): array
28 40
    {
29
        return $this->getList('plugins');
30 40
    }
31
32
    public function vendor(): string
33 30
    {
34
        return Illuminate::get($this->privateKey() . '.path.base');
35 30
    }
36
37 30
    public function resources(): string
38 30
    {
39
        return Illuminate::get($this->privateKey() . '.path.target');
40 30
    }
41
42
    public function source(): string
43
    {
44
        return Illuminate::get($this->privateKey() . '.path.source');
45
    }
46
47
    public function locales(): string
48 43
    {
49
        return Illuminate::get($this->privateKey() . '.path.locales');
50 43
    }
51
52 43
    public function excludes(): array
53
    {
54
        return Illuminate::get($this->publicKey() . '.exclude', []);
55
    }
56
57
    public function ignores(): array
58
    {
59
        return Illuminate::get($this->publicKey() . '.ignore', []);
60 43
    }
61
62 43
    public function getCase(): int
63
    {
64 43
        return Illuminate::get($this->publicKey() . '.case', Caseable::NO_CASE);
65
    }
66
67
    public function defaultLocale(): string
68
    {
69
        return Illuminate::get('app.locale') ?: $this->fallbackLocale();
70
    }
71
72 36
    public function fallbackLocale(): string
73
    {
74 36
        return Illuminate::get('app.fallback_locale') ?: LocalesList::ENGLISH;
75
    }
76 36
77
    public function hasInline(): bool
78
    {
79
        return Illuminate::get($this->publicKey() . '.inline');
80
    }
81
82
    public function hasAlignment(): bool
83
    {
84 43
        return Illuminate::get($this->publicKey() . '.alignment');
85
    }
86 43
87
    protected function getList(string $key): array
88 43
    {
89
        $private = Illuminate::get($this->privateKey() . '.' . $key, []);
90
        $public  = Illuminate::get($this->publicKey() . '.' . $key, []);
91
92
        return array_values(array_merge($private, $public));
93
    }
94
95
    protected function privateKey(): string
96 30
    {
97
        return ConfigNames::KEY_PRIVATE;
98 30
    }
99
100 30
    protected function publicKey(): string
101
    {
102
        return ConfigNames::KEY_PUBLIC;
103
    }
104
}
105