Passed
Push — master ( 5803a7...e17c3d )
by Andrey
26:12 queued 23:37
created

Config   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
eloc 14
dl 0
loc 91
ccs 21
cts 21
cp 1
rs 10
c 3
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A key() 0 3 1
A getExclude() 0 5 1
A getFallbackLocale() 0 3 1
A getLocale() 0 4 2
A getVendorPath() 0 3 1
A isInline() 0 3 1
A getCase() 0 3 1
A config() 0 5 1
A isAlignment() 0 3 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\PrettyArray\Contracts\Caseable;
6
use Illuminate\Support\Facades\Config as IlluminateConfig;
7
8
final class Config
9
{
10
    public const KEY = 'lang-publisher';
11
12
    /**
13
     * Getting a link to the folder with the source localization files.
14
     *
15
     * @return string
16
     */
17 48
    public function getVendorPath(): string
18
    {
19 48
        return realpath(__DIR__ . '/../../vendor/caouecs/laravel-lang/src');
20
    }
21
22
    /**
23
     * Getting the default localization name.
24
     *
25
     * @return string
26
     */
27 12
    public function getLocale(): string
28
    {
29 12
        return IlluminateConfig::get('app.locale')
30 12
            ?: IlluminateConfig::get('app.fallback_locale', 'en');
31
    }
32
33
    /**
34
     * Getting the fallback localization name.
35
     *
36
     * @return string
37
     */
38 6
    public function getFallbackLocale(): string
39
    {
40 6
        return IlluminateConfig::get('app.fallback_locale', 'en');
41
    }
42
43
    /**
44
     * Will array alignment be applied.
45
     *
46
     * @return bool
47
     */
48 12
    public function isAlignment(): bool
49
    {
50 12
        return (bool) $this->config('alignment', true);
51
    }
52
53
    /**
54
     * Returns an array of exceptions set by the developer
55
     * when installing and updating localizations.
56
     *
57
     * @param  string  $key
58
     * @param  array  $default
59
     *
60
     * @return array
61
     */
62 12
    public function getExclude(string $key, array $default = []): array
63
    {
64 12
        $exclude = $this->config('exclude', []);
65
66 12
        return $exclude[$key] ?? $default;
67
    }
68
69
    /**
70
     * Returns the key mapping label.
71
     *
72
     * @return int
73
     */
74 12
    public function getCase(): int
75
    {
76 12
        return $this->config('case', Caseable::NO_CASE);
77
    }
78
79
    /**
80
     * Determines what type of files to use when updating language files.
81
     *
82
     * @return bool
83
     */
84 12
    public function isInline(): bool
85
    {
86 12
        return $this->config('inline', false);
87
    }
88
89 12
    protected function config(string $key, $default = null)
90
    {
91 12
        $key = $this->key($key);
92
93 12
        return IlluminateConfig::get($key, $default);
94
    }
95
96 12
    protected function key(string $key): string
97
    {
98 12
        return self::KEY . '.' . $key;
99
    }
100
}
101