Completed
Pull Request — master (#285)
by Luc
07:52
created

CultureFeedAddressFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B fromCdbAddress() 0 29 4
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
            'zip code' => $cdbAddress->getZip(),
18
            'city' => $cdbAddress->getCity(),
19
            'country' => $cdbAddress->getCountry(),
20
        ];
21
22
        $missingFields = [];
23
        foreach ($requiredFields as $key => $requiredField) {
24
            if (is_null($requiredField)) {
25
                $missingFields[] = $key;
26
            }
27
        }
28
29
        if (count($missingFields) > 0) {
30
            $keys = implode(', ', $missingFields);
31
            throw new \InvalidArgumentException('The given cdbxml address is missing a ' . $keys);
32
        }
33
34
35
        return new Address(
36
            new Street($cdbAddress->getStreet() . ' ' . $cdbAddress->getHouseNumber()),
37
            new PostalCode($cdbAddress->getZip()),
38
            new Locality($cdbAddress->getCity()),
39
            Country::fromNative($cdbAddress->getCountry())
40
        );
41
    }
42
}
43