Passed
Push — master ( dc765b...d220c6 )
by Andrey
130:03 queued 111:34
created

Config::getFallbackLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
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\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 $this->config('vendor');
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
    protected function config(string $key, $default = null)
79
    {
80 48
        $key = $this->key($key);
81
82 48
        return IlluminateConfig::get($key, $default);
83
    }
84
85 48
    protected function key(string $key): string
86
    {
87 48
        return self::KEY . '.' . $key;
88
    }
89
}
90