Completed
Push — scrutinizer ( 42ac6a...7bc18e )
by z38
02:40
created

UnstructuredPostalAddress   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 5
c 4
b 2
f 1
lcom 1
cbo 0
dl 0
loc 46
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A asDom() 0 11 2
1
<?php
2
3
namespace Z38\SwissPayment;
4
5
/**
6
 * This class holds a unstructured representation of a postal address
7
 */
8
class UnstructuredPostalAddress implements PostalAddressInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $addressLines;
14
15
    /**
16
     * @var string
17
     */
18
    protected $country;
19
20
    /**
21
     * Constructor
22
     *
23
     * @param string $addressLine1 Street name and house number
24
     * @param string $addressLine2 Postcode and town
25
     * @param string $country      Country code (ISO 3166-1 alpha-2)
26
     */
27 2
    public function __construct($addressLine1 = null, $addressLine2 = null, $country = 'CH')
28
    {
29 2
        $this->addressLines = array();
30 2
        if ($addressLine1 !== null) {
31 2
            $this->addressLines[] = $addressLine1;
32 2
        }
33 2
        if ($addressLine2 !== null) {
34 2
            $this->addressLines[] = $addressLine2;
35 2
        }
36 2
        $this->country = (string) $country;
37 2
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    public function asDom(\DOMDocument $doc)
43
    {
44 2
        $root = $doc->createElement('PstlAdr');
45
46 2
        $root->appendChild($doc->createElement('Ctry', $this->country));
47 2
        foreach ($this->addressLines as $line) {
48 2
            $root->appendChild($doc->createElement('AdrLine', $line));
49 2
        }
50
51 2
        return $root;
52
    }
53
}
54