Language   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 63
loc 63
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 4 4 1
A name() 4 4 1
A all() 7 7 1
A data() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}