RegionMapper::mapArrayToEntity()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 19
cts 19
cp 1
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 1
crap 2
1
<?php
2
3
namespace GeoBase\Regions\Region;
4
5
use GeoBase\Regions\Region\RegionName\RegionNameEntity;
6
7
class RegionMapper
8
{
9
    /**
10
     * @param array $data
11
     *
12
     * @return RegionCollection
13
     */
14 2
    public function mapArrayToCollection(array $data)
15
    {
16 2
        $collection = new RegionCollection();
17 2
        foreach ($data as $attributes) {
18 2
            $region = $this->mapArrayToEntity($attributes);
19 2
            if (null !== $region) {
20 2
                $collection->add($region);
21
            }
22
        }
23
24 2
        return $collection;
25
    }
26
27
    /**
28
     * @param array $attributes
29
     *
30
     * @return RegionEntity
31
     */
32 4
    public function mapArrayToEntity(array $attributes)
33
    {
34 4
        $region = new RegionEntity();
35 4
        $region->setCode($attributes['code']);
36 4
        $region->setLongCode($attributes['long_code']);
37 4
        $region->setType($attributes['type']);
38 4
        $region->setUnmappedCountry($attributes['country']);
39 4
        $region->setTimezone($attributes['timezone']);
40 4
        $region->setLatitude($attributes['latitude']);
41 4
        $region->setLongitude($attributes['longitude']);
42 4
        $region->setNorth($attributes['north']);
43 4
        $region->setEast($attributes['east']);
44 4
        $region->setSouth($attributes['south']);
45 4
        $region->setWest($attributes['west']);
46
47 4
        foreach ($attributes['names'] as $language => $name) {
48 4
            $regionName = new RegionNameEntity();
49 4
            $regionName->setLanguage($language);
50 4
            $regionName->setName($name);
51 4
            $region->getNames()->add($regionName);
52
        }
53
54 4
        return $region;
55
    }
56
}
57