Completed
Pull Request — master (#285)
by Luc
04:48
created

CultureFeedAddressFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromCdbAddress() 0 23 3
1
<?php
2
3
namespace CultuurNet\UDB3\Address;
4
5
use ValueObjects\Geography\Country;
6
7
class CultureFeedAddressFactory implements CultureFeedAddressFactoryInterface
8
{
9
    /**
10
     * @param \CultureFeed_Cdb_Data_Address_PhysicalAddress $cdbAddress
11
     * @return Address
12
     */
13
    public function fromCdbAddress(\CultureFeed_Cdb_Data_Address_PhysicalAddress $cdbAddress)
14
    {
15
        $requiredFields = [
16
            'street' => $cdbAddress->getStreet(),
17
            'house number' => $cdbAddress->getHouseNumber(),
18
            'zip code' => $cdbAddress->getZip(),
19
            'city' => $cdbAddress->getCity(),
20
            'country' => $cdbAddress->getCountry(),
21
        ];
22
23
        foreach ($requiredFields as $key => $requiredField) {
24
            if (is_null($requiredField)) {
25
                throw new \InvalidArgumentException('The given cdbxml address is missing a ' . $key);
26
            }
27
        }
28
29
        return new Address(
30
            new Street($cdbAddress->getStreet() . ' ' . $cdbAddress->getHouseNumber()),
31
            new PostalCode($cdbAddress->getZip()),
32
            new Locality($cdbAddress->getCity()),
33
            Country::fromNative($cdbAddress->getCountry())
34
        );
35
    }
36
}
37