Completed
Push — master ( 5ffa00...bbd465 )
by Chin
01:16
created

helpers.php ➔ locale()   A

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
     * @return array
8
     */
9
    function locales() : array
10
    {
11
        return config('app.locales') ?? config('laravel-locales.supported');
12
    }
13
}
14
15
if (! function_exists('locale')) {
16
    /**
17
     * Retrieve the current locale of the application.
18
     *
19
     * @param  string  $locale
20
     * @return string
21
     */
22
    function locale(string $locale = null) : string
23
    {
24
        if ($locale && in_array($locale, locales())) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $locale of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
25
            app()->setLocale($locale);
26
        }
27
28
        return app()->getLocale();
29
    }
30
}
31