CountryMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
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 53
ccs 29
cts 29
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 27 2
1
<?php
2
3
namespace GeoBase\Countries\Country;
4
5
use GeoBase\Countries\Country\CountryName\CountryNameEntity;
6
7
class CountryMapper
8
{
9
    /**
10
     * @param array $data
11
     *
12
     * @return CountryCollection
13
     */
14 2
    public function mapArrayToCollection(array $data)
15
    {
16 2
        $collection = new CountryCollection();
17 2
        foreach ($data as $attributes) {
18 2
            $country = $this->mapArrayToEntity($attributes);
19 2
            if (null !== $country) {
20 2
                $collection->add($country);
21
            }
22
        }
23
24 2
        return $collection;
25
    }
26
27
    /**
28
     * @param array $attributes
29
     *
30
     * @return CountryEntity
31
     */
32 4
    public function mapArrayToEntity(array $attributes)
33
    {
34 4
        $country = new CountryEntity();
35 4
        $country->setCode($attributes['code']);
36 4
        $country->setShortCode($attributes['shortCode']);
37 4
        $country->setLatitude($attributes['latitude']);
38 4
        $country->setLongitude($attributes['longitude']);
39 4
        $country->setCurrency($attributes['currency']);
40 4
        $country->setContinent($attributes['continent']);
41 4
        $country->setPopulation($attributes['population']);
42 4
        $country->setArea($attributes['area']);
43 4
        $country->setCapital($attributes['capital']);
44 4
        $country->setTimezone($attributes['timezone']);
45 4
        $country->setNorth($attributes['north']);
46 4
        $country->setEast($attributes['east']);
47 4
        $country->setSouth($attributes['south']);
48 4
        $country->setWest($attributes['west']);
49
50 4
        foreach ($attributes['names'] as $language => $name) {
51 4
            $countryName = new CountryNameEntity();
52 4
            $countryName->setLanguage($language);
53 4
            $countryName->setName($name);
54 4
            $country->getNames()->add($countryName);
55
        }
56
57 4
        return $country;
58
    }
59
}
60