Passed
Pull Request — main (#96)
by Andrey
50:33 queued 35:34
created

Config::sourcePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Concerns\Logger;
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
    use Logger;
0 ignored issues
show
Bug introduced by
The trait Helldar\LaravelLangPublisher\Concerns\Logger requires the property $output which is not provided by Helldar\LaravelLangPublisher\Support\Config.
Loading history...
13
14
    public const KEY_PRIVATE = 'lang-publisher-private';
15
16
    public const KEY_PUBLIC = 'lang-publisher';
17
18
    /**
19
     * Getting a list of packages from which to synchronize localization files.
20
     *
21
     * @return array
22
     */
23 16
    public function packages(): array
24
    {
25 16
        $this->log('Getting a list of supported packages...');
26
27 16
        $private = Illuminate::get(self::KEY_PRIVATE . '.packages', []);
28
        $public  = Illuminate::get(self::KEY_PUBLIC . '.packages', []);
29
30
        return array_values(array_merge($public, $private));
31
    }
32
33
    /**
34
     * Getting the path to the sources of the English localization.
35 7
     *
36
     * @return string
37 7
     */
38
    public function basePath(): string
39 7
    {
40
        $this->log('Getting the path to the sources of the English localization...');
41
42
        return Illuminate::get(self::KEY_PRIVATE . '.path.base');
43
    }
44
45
    /**
46
     * Getting the path to source locale.
47 16
     *
48
     * @return string
49 16
     */
50
    public function sourcePath(): string
51 16
    {
52
        $this->log('Getting the path to source locale...');
53
54
        return Illuminate::get(self::KEY_PRIVATE . '.path.source');
55
    }
56
57
    /**
58
     * Getting the path to localizations.
59 11
     *
60
     * @return string
61 11
     */
62
    public function localesPath(): string
63 11
    {
64
        $this->log('Getting the path to localizations...');
65
66
        return Illuminate::get(self::KEY_PRIVATE . '.path.locales');
67
    }
68
69
    /**
70
     * Getting the path to resources of the application.
71 11
     *
72
     * @return string
73 11
     */
74
    public function resourcesPath(): string
75 11
    {
76
        $this->log('Getting the path to resources of the application...');
77
78
        return Illuminate::get(self::KEY_PRIVATE . '.path.target');
79
    }
80
81
    /**
82
     * Determines what type of files to use when updating language files.
83 10
     *
84
     * @return bool
85 10
     */
86
    public function hasInline(): bool
87 10
    {
88
        $this->log('Determines what type of files to use when updating language files...');
89
90
        return Illuminate::get(self::KEY_PUBLIC . '.inline');
91
    }
92
93
    /**
94
     * Determines whether values should be aligned when saving.
95 10
     *
96
     * @return bool
97 10
     */
98
    public function hasAlignment(): bool
99 10
    {
100
        $this->log('Determines whether values should be aligned when saving...');
101
102
        return Illuminate::get(self::KEY_PUBLIC . '.alignment');
103
    }
104
105
    /**
106
     * Key exclusion when combining.
107 11
     *
108
     * @return array
109 11
     */
110
    public function excludes(): array
111 11
    {
112
        $this->log('Key exclusion when combining...');
113
114
        return Illuminate::get(self::KEY_PUBLIC . '.exclude', []);
115
    }
116
117
    /**
118
     * List of ignored localizations.
119 4
     *
120
     * @return array
121 4
     */
122
    public function ignores(): array
123 4
    {
124
        $this->log('List of ignored localizations...');
125
126
        return Illuminate::get(self::KEY_PUBLIC . '.ignore', []);
127
    }
128
129
    /**
130
     * Getting the value of the option to change the case of keys.
131 3
     *
132
     * @return int
133 3
     */
134
    public function getCase(): int
135 3
    {
136
        $this->log('Getting the value of the option to change the case of keys...');
137
138
        return Illuminate::get(self::KEY_PUBLIC . '.case', Caseable::NO_CASE);
139
    }
140
141
    /**
142
     * Getting the default localization name.
143
     *
144
     * @return string
145
     */
146
    public function defaultLocale(): string
147
    {
148
        $this->log('Getting the default localization name...');
149
150
        return Illuminate::get('app.locale') ?: $this->fallbackLocale();
151
    }
152
153
    /**
154
     * Getting the fallback localization name.
155
     *
156
     * @return string
157
     */
158
    public function fallbackLocale(): string
159
    {
160
        $this->log('Getting the fallback localization name...');
161
162
        return Illuminate::get('app.fallback_locale') ?: LocalesList::ENGLISH;
163
    }
164
}
165