InternationalInfoManager::country()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace InternationalInfo;
4
5
class InternationalInfoManager
6
{
7
    protected array $instances = [];
8
9 7
    public function storageFile(string $name): string
10
    {
11 7
        $file = config('international-info.storage_path') . '/' . $name;
12 7
        if (file_exists($file)) {
13 1
            return $file;
14
        }
15
16 6
        return __DIR__ . '/../storage/international-info/' . $name;
17
    }
18
19 1
    public function continent(): Continent
20
    {
21 1
        if (!empty($this->instances[ __FUNCTION__ ])) {
22 1
            return $this->instances[ __FUNCTION__ ];
23
        }
24
25 1
        return $this->instances[ __FUNCTION__ ] = new Continent(include($this->storageFile('continents.php')));
26
    }
27
28 2
    public function country(): Country
29
    {
30 2
        if (!empty($this->instances[ __FUNCTION__ ])) {
31 1
            return $this->instances[ __FUNCTION__ ];
32
        }
33
34 2
        return $this->instances[ __FUNCTION__ ] = new Country(include($this->storageFile('countries.php')));
35
    }
36
37 1
    public function localeData(): LocaleData
38
    {
39 1
        if (!empty($this->instances[ __FUNCTION__ ])) {
40 1
            return $this->instances[ __FUNCTION__ ];
41
        }
42
43 1
        return $this->instances[ __FUNCTION__ ] = new LocaleData(include($this->storageFile('locale-data.php')));
44
    }
45
46 1
    public function phoneCode(): PhoneCode
47
    {
48 1
        if (!empty($this->instances[ __FUNCTION__ ])) {
49 1
            return $this->instances[ __FUNCTION__ ];
50
        }
51
52 1
        return $this->instances[ __FUNCTION__ ] = new PhoneCode(include($this->storageFile('phone-codes.php')));
53
    }
54
55 2
    public function state(): State
56
    {
57 2
        if (!empty($this->instances[ __FUNCTION__ ])) {
58 1
            return $this->instances[ __FUNCTION__ ];
59
        }
60
61 2
        return $this->instances[ __FUNCTION__ ] = new State(include($this->storageFile('states.php')));
62
    }
63
}
64