RegionLoader::loadRegion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GeoBase\Regions\Region;
4
5
use GeoBase\CountriesData\CountriesData;
6
7
class RegionLoader
8
{
9
    const ALL_REGIONS_FILE = 'regions.json';
10
    const REGION_FILE = 'regions/%s.json';
11
    const REGION_POLYGON_FILE = 'regions/%s/polygon.json';
12
13
    /**
14
     * @var string
15
     */
16
    private $path;
17
18 3
    public function __construct()
19
    {
20 3
        $this->path = CountriesData::getRegionsPath();
21 3
    }
22
23
    /**
24
     * @return array
25
     */
26 3
    public function loadAllRegions()
27
    {
28 3
        return json_decode(
29 3
            file_get_contents($this->path.DIRECTORY_SEPARATOR.self::ALL_REGIONS_FILE),
30 3
            true
31
        );
32
    }
33
34
    /**
35
     * @param string $region
36
     *
37
     * @return array
38
     */
39 1 View Code Duplication
    public function loadRegion($region)
0 ignored issues
show
Duplication introduced by
This method 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...
40
    {
41 1
        return json_decode(
42
            file_get_contents(
43 1
                $this->path.DIRECTORY_SEPARATOR.sprintf(self::REGION_FILE, $region)
44
            ),
45 1
            true
46
        );
47
    }
48
49
    /**
50
     * @param string $region
51
     *
52
     * @return array
53
     */
54 View Code Duplication
    public function loadRegionPolygon($region)
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        return json_decode(
57
            file_get_contents(
58
                $this->path.DIRECTORY_SEPARATOR.sprintf(self::REGION_POLYGON_FILE, $region)
59
            ),
60
            true
61
        );
62
    }
63
}
64