helpers.php ➔ locale()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('locales')) {
4
    /**
5
     * Retrieve the supported locales of the application.
6
     *
7
     * @param  array  $locales
8
     * @return array
9
     */
10
    function locales(array $locales = null): array
11
    {
12
        if (! is_null($locales)) {
13
            config([
14
                'app.locales' => $locales,
15
                'locales.supported' => $locales,
16
            ]);
17
        }
18
19
        $locales = config('app.locales') ?? config('locales.supported');
20
21
        return isset($locales[0]) ? $locales : array_keys($locales);
22
    }
23
}
24
25
if (! function_exists('locale')) {
26
    /**
27
     * Retrieve the current locale of the application.
28
     *
29
     * @param  string  $locale
30
     * @return string
31
     */
32
    function locale(string $locale = null): string
33
    {
34
        if (! is_null($locale) && in_array($locale, locales())) {
35
            app()->setLocale($locale);
36
        }
37
38
        return app()->getLocale();
39
    }
40
}
41