Language::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 4
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Propaganistas\LaravelIntl;
4
5
use Illuminate\Support\Arr;
6
use Propaganistas\LaravelIntl\Concerns\WithLocales;
7
use Propaganistas\LaravelIntl\Contracts\Intl;
8
9 View Code Duplication
class Language extends Intl
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    use WithLocales;
12
13
    /**
14
     * Loaded localized country data.
15
     *
16
     * @var array
17
     */
18
    protected $data;
19
20
    /**
21
     * Get a localized record by key.
22
     *
23
     * @param string $key
24
     * @return mixed
25
     */
26 18
    public function get($key)
27
    {
28 18
        return Arr::get($this->all(), $key);
29
    }
30
31
    /**
32
     * Alias of get().
33
     *
34
     * @param string $key
35
     * @return string
36
     */
37 15
    public function name($key)
38
    {
39 15
        return $this->get($key);
40
    }
41
42
    /**
43
     * Get all localized records.
44
     *
45
     * @return array
46
     */
47 21
    public function all()
48
    {
49 21
        $default = $this->data($this->getLocale());
50 21
        $fallback = $this->data($this->getFallbackLocale());
51
52 21
        return $default + $fallback;
53
    }
54
55
    /**
56
     * Load the data for the given locale.
57
     *
58
     * @param string $locale
59
     * @return array
60
     */
61 21
    protected function data($locale)
62
    {
63 21
        if (! isset($this->data[$locale])) {
64 21
            $path = base_path('vendor/umpirsky/locale-list/data/'.$locale.'/locales.php');
65
66 21
            $this->data[$locale] = is_file($path) ? require $path : [];
67
        }
68
69 21
        return $this->data[$locale];
70
    }
71
}