RegionMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 50
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mapArrayToCollection() 0 12 3
B mapArrayToEntity() 0 24 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