Completed
Push — master ( 59ace0...1e869a )
by Propa
03:14
created

Language::data()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
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
class Language extends Intl
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
}