Code Duplication    Length = 120-120 lines in 2 locations

src/Country.php 1 location

@@ 8-127 (lines=120) @@
5
use Illuminate\Support\Arr;
6
use Propaganistas\LaravelIntl\Contracts\Intl;
7
8
class Country extends Intl
9
{
10
    /**
11
     * Loaded localized country data.
12
     *
13
     * @var array
14
     */
15
    protected $data;
16
17
    /**
18
     * The current locale.
19
     *
20
     * @var string $locale
21
     */
22
    protected $locale;
23
24
    /**
25
     * The current locale.
26
     *
27
     * @var string $locale
28
     */
29
    protected $fallbackLocale;
30
31
    /**
32
     * Get a localized record by key.
33
     *
34
     * @param string $key
35
     * @return string
36
     */
37
    public function get($key)
38
    {
39
        return Arr::get($this->all(), $key);
40
    }
41
42
    /**
43
     * Alias of get().
44
     *
45
     * @param string $key
46
     * @return string
47
     */
48
    public function name($key)
49
    {
50
        return $this->get($key);
51
    }
52
53
    /**
54
     * Get all localized records.
55
     *
56
     * @return array
57
     */
58
    public function all()
59
    {
60
        return $this->data[$this->getLocale()] + $this->data[$this->getFallbackLocale()];
61
    }
62
63
    /**
64
     * Get the current locale.
65
     *
66
     * @return string
67
     */
68
    public function getLocale()
69
    {
70
        return $this->locale;
71
    }
72
73
    /**
74
     * Set the current locale.
75
     *
76
     * @param $locale
77
     * @return $this
78
     */
79
    public function setLocale($locale)
80
    {
81
        $this->locale = $locale;
82
83
        $this->load($locale);
84
85
        return $this;
86
    }
87
88
    /**
89
     * Get the fallback locale.
90
     *
91
     * @return string
92
     */
93
    public function getFallbackLocale()
94
    {
95
        return $this->fallbackLocale;
96
    }
97
98
    /**
99
     * Set the fallback locale.
100
     *
101
     * @param $locale
102
     * @return $this
103
     */
104
    public function setFallbackLocale($locale)
105
    {
106
        $this->fallbackLocale = $locale;
107
108
        $this->load($locale);
109
110
        return $this;
111
    }
112
113
    /**
114
     * Load the data for the given locale.
115
     *
116
     * @param string $locale
117
     * @return void
118
     */
119
    protected function load($locale)
120
    {
121
        if (! isset($this->data[$locale])) {
122
            $path = base_path('vendor/umpirsky/country-list/data/'.$locale.'/country.php');
123
124
            $this->data[$locale] = is_file($path) ? require $path : [];
125
        }
126
    }
127
}

src/Language.php 1 location

@@ 8-127 (lines=120) @@
5
use Illuminate\Support\Arr;
6
use Propaganistas\LaravelIntl\Contracts\Intl;
7
8
class Language extends Intl
9
{
10
    /**
11
     * Loaded localized country data.
12
     *
13
     * @var array
14
     */
15
    protected $data;
16
17
    /**
18
     * The current locale.
19
     *
20
     * @var string $locale
21
     */
22
    protected $locale;
23
24
    /**
25
     * The current locale.
26
     *
27
     * @var string $locale
28
     */
29
    protected $fallbackLocale;
30
31
    /**
32
     * Get a localized record by key.
33
     *
34
     * @param string $key
35
     * @return mixed
36
     */
37
    public function get($key)
38
    {
39
        return Arr::get($this->all(), $key);
40
    }
41
42
    /**
43
     * Alias of get().
44
     *
45
     * @param string $key
46
     * @return string
47
     */
48
    public function name($key)
49
    {
50
        return $this->get($key);
51
    }
52
53
    /**
54
     * Get all localized records.
55
     *
56
     * @return array
57
     */
58
    public function all()
59
    {
60
        return $this->data[$this->getLocale()] + $this->data[$this->getFallbackLocale()];
61
    }
62
63
    /**
64
     * Get the current locale.
65
     *
66
     * @return string
67
     */
68
    public function getLocale()
69
    {
70
        return $this->locale;
71
    }
72
73
    /**
74
     * Set the current locale.
75
     *
76
     * @param $locale
77
     * @return $this
78
     */
79
    public function setLocale($locale)
80
    {
81
        $this->locale = $locale;
82
83
        $this->load($locale);
84
85
        return $this;
86
    }
87
88
    /**
89
     * Get the fallback locale.
90
     *
91
     * @return string
92
     */
93
    public function getFallbackLocale()
94
    {
95
        return $this->fallbackLocale;
96
    }
97
98
    /**
99
     * Set the fallback locale.
100
     *
101
     * @param $locale
102
     * @return $this
103
     */
104
    public function setFallbackLocale($locale)
105
    {
106
        $this->fallbackLocale = $locale;
107
108
        $this->load($locale);
109
110
        return $this;
111
    }
112
113
    /**
114
     * Load the data for the given locale.
115
     *
116
     * @param string $locale
117
     * @return void
118
     */
119
    protected function load($locale)
120
    {
121
        if (! isset($this->data[$locale])) {
122
            $path = base_path('vendor/umpirsky/locale-list/data/'.$locale.'/locales.php');
123
124
            $this->data[$locale] = is_file($path) ? require $path : [];
125
        }
126
    }
127
}