Passed
Pull Request — master (#53)
by Andrey
12:07
created

Config   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
eloc 13
c 3
b 0
f 0
dl 0
loc 89
ccs 19
cts 19
cp 1
rs 10

9 Methods

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