Passed
Push — master ( 6bed8c...33ba8b )
by Manuel
01:36
created

StructuredAddress::getStreet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sprain\SwissQrBill\DataGroups;
4
5
use Sprain\SwissQrBill\DataGroups\Abstracts\Address;
6
use Symfony\Component\Validator\Constraints as Assert;
7
use Symfony\Component\Validator\Mapping\ClassMetadata;
8
9
class StructuredAddress extends Address
10
{
11
    const ADDRESS_TYPE = 'S';
12
13
    /**
14
     * Street / P.O. box 
15
     *
16
     * May not include building or house number.
17
     *
18
     * @var string
19
     */
20
    private $street;
21
22
    /**
23
     * Building number 
24
     *
25
     * @var string
26
     */
27
    private $buildingNumber;
28
29
    /**
30
     * Postal code without county code
31
     *
32
     * @var string
33
     */
34
    private $postalCode;
35
36
    /**
37
     * City
38
     *
39
     * @var string
40
     */
41
    private $city;
42
43
    public function getStreet(): ?string
44
    {
45
        return $this->street;
46
    }
47
48
    public function setStreet(string $street = null) : self
49
    {
50
        $this->street = $street;
51
52
        return $this;
53
    }
54
55
    public function getBuildingNumber(): ?string
56
    {
57
        return $this->buildingNumber;
58
    }
59
60
    public function setBuildingNumber(string $buildingNumber = null) : self
61
    {
62
        $this->buildingNumber = $buildingNumber;
63
64
        return $this;
65
    }
66
67
    public function getPostalCode(): ?string
68
    {
69
        return $this->postalCode;
70
    }
71
72
    public function setPostalCode(string $postalCode) : self
73
    {
74
        $this->postalCode = $postalCode;
75
76
        return $this;
77
    }
78
79
    public function getCity(): ?string
80
    {
81
        return $this->city;
82
    }
83
84
    public function setCity(string $city) : self
85
    {
86
        $this->city = $city;
87
88
        return $this;
89
    }
90
91
    public function getFullAddress() : string
92
    {
93
        $address = $this->getName();
94
95
        if ($this->getStreet()) {
96
            $address .= "\n" . $this->getStreet();
97
98
            if ($this->getBuildingNumber()) {
99
                $address .= " " . $this->getBuildingNumber();
100
            }
101
        }
102
103
        $address .= sprintf("\n%s-%s %s", $this->getCountry(), $this->getPostalCode(), $this->getCity());
104
105
        return $address;
106
    }
107
108
    public function getQrCodeData() : array
109
    {
110
        return [
111
            self::ADDRESS_TYPE,
112
            $this->getName(),
113
            $this->getStreet(),
114
            $this->getBuildingNumber(),
115
            $this->getPostalCode(),
116
            $this->getCity(),
117
            $this->getCountry()
118
        ];
119
    }
120
121
    public static function loadValidatorMetadata(ClassMetadata $metadata)
122
    {
123
        $metadata->addPropertyConstraints('street', [
124
            new Assert\Length([
125
                'max' => 70
126
            ])
127
        ]);
128
129
        $metadata->addPropertyConstraints('buildingNumber', [
130
            new Assert\Length([
131
                'max' => 16
132
            ])
133
        ]);
134
135
        $metadata->addPropertyConstraints('postalCode', [
136
            new Assert\NotBlank(),
137
            new Assert\Length([
138
                'max' => 16
139
            ])
140
        ]);
141
142
        $metadata->addPropertyConstraints('city', [
143
            new Assert\NotBlank(),
144
            new Assert\Length([
145
                'max' => 35
146
            ])
147
        ]);
148
    }
149
}