Translatable::normalizeLocale()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 3
1
<?php
2
3
namespace MikeZange\LaravelDatabaseTranslation;
4
5
use Spatie\Translatable\HasTranslations;
6
7
trait Translatable
8
{
9
    use HasTranslations;
10
11
    /**
12
     * @param string $key
13
     * @param string $locale
14
     * @param bool   $useFallbackLocale
15
     *
16
     * @return mixed|string
17
     */
18
    protected function normalizeLocale(string $key, string $locale, bool $useFallbackLocale) : string
19
    {
20
        if (in_array($locale, $this->getTranslatedLocales($key))) {
21
            return $locale;
22
        }
23
24
        if (!$useFallbackLocale) {
25
            return $locale;
26
        }
27
28
        if (!is_null($fallbackLocale = config('app.fallback_locale'))) {
29
            return $fallbackLocale;
30
        }
31
32
        return $locale;
33
    }
34
}
35