Completed
Push — master ( 5a826a...3b609b )
by Mike
06:09
created

Translatable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 31
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
     *
14
     * @param string $locale
15
     * @param bool $useFallbackLocale
16
     *
17
     * @return mixed|string
18
     */
19
20
21
    protected function normalizeLocale(string $key, string $locale, bool $useFallbackLocale) : string
22
    {
23
        if (in_array($locale, $this->getTranslatedLocales($key))) {
24
            return $locale;
25
        }
26
27
        if (!$useFallbackLocale) {
28
            return $locale;
29
        }
30
31
        if (!is_null($fallbackLocale = config('app.fallback_locale'))) {
32
            return $fallbackLocale;
33
        }
34
35
        return $locale;
36
    }
37
}
38