Translatable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalizeLocale() 0 16 4
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