Config::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Constants\Locales;
6
use Helldar\PrettyArray\Contracts\Caseable;
7
use Illuminate\Support\Arr as IlluminateArr;
8
use Illuminate\Support\Facades\Config as IlluminateConfig;
9
10
final class Config
11
{
12
    public const KEY = 'lang-publisher';
13
14
    public const KEY_PRIVATE = 'lang-publisher-private';
15
16
    /**
17 102
     * Getting a link to the folder with the source localization files.
18
     *
19 102
     * @return string
20
     */
21
    public function getVendorPath(): string
22
    {
23
        $path = IlluminateConfig::get(self::KEY_PRIVATE . '.vendor');
24
25
        return rtrim($path, '\\/');
26
    }
27 30
28
    /**
29 30
     * Getting the default localization name.
30 30
     *
31
     * @return string
32
     */
33
    public function getLocale(): string
34
    {
35
        return IlluminateConfig::get('app.locale') ?: $this->getFallbackLocale();
36
    }
37
38 6
    /**
39
     * Getting the fallback localization name.
40 6
     *
41
     * @return string
42
     */
43
    public function getFallbackLocale(): string
44
    {
45
        return IlluminateConfig::get('app.fallback_locale', Locales::ENGLISH);
46
    }
47
48 12
    /**
49
     * Will array alignment be applied.
50 12
     *
51
     * @return bool
52
     */
53
    public function isAlignment(): bool
54
    {
55
        return (bool) $this->config('alignment', true);
56
    }
57
58
    /**
59
     * Returns an array of exceptions set by the developer
60
     * when installing and updating localizations.
61
     *
62
     * @param  string  $key
63 30
     * @param  array  $default
64
     * @param  bool  $is_json
65 30
     *
66
     * @return array
67 30
     */
68 18
    public function getExclude(string $key, array $default = [], bool $is_json = false): array
69 30
    {
70
        $exclude = $this->config('exclude', []);
71
72
        return $is_json
73
            ? $exclude
74
            : IlluminateArr::get($exclude, $key, $default);
75
    }
76
77 12
    public function getIgnore(): array
78
    {
79 12
        return $this->config('ignore', []);
80
    }
81
82
    /**
83
     * Returns the key mapping label.
84
     *
85
     * @return int
86
     */
87 30
    public function getCase(): int
88
    {
89 30
        return $this->config('case', Caseable::NO_CASE);
90
    }
91
92 102
    /**
93
     * Determines what type of files to use when updating language files.
94 102
     *
95
     * @return bool
96 102
     */
97
    public function isInline(): bool
98
    {
99 102
        return $this->config('inline', false);
100
    }
101 102
102
    protected function config(string $key, $default = null)
103
    {
104
        $key = $this->key($key);
105
106
        return IlluminateConfig::get($key, $default);
107
    }
108
109
    protected function key(string $key): string
110
    {
111
        return self::KEY . '.' . $key;
112
    }
113
}
114