Completed
Push — master ( 31cc79...dd89a0 )
by Manuel
05:17
created

CombinedAddress::getAddressLine2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sprain\SwissQrBill\DataGroup;
4
5
use Sprain\SwissQrBill\DataGroup\Abstracts\Address;
6
use Symfony\Component\Validator\Constraints as Assert;
7
use Symfony\Component\Validator\Mapping\ClassMetadata;
8
9
class CombinedAddress extends Address
10
{
11
    const ADDRESS_TYPE = 'K';
12
13
    /**
14
     * Address line 1
15
     *
16
     * Street and building number or P.O. Box
17
     *
18
     * @var string
19
     */
20
    private $addressLine1;
21
22
    /**
23
     * Address line 2
24
     *
25
     * Postal code and town
26
     *
27
     * @var string
28
     */
29
    private $addressLine2;
30
31
    public function getAddressLine1(): ?string
32
    {
33
        return $this->addressLine1;
34
    }
35
36
    public function setAddressLine1(string $addressLine1 = null): self
37
    {
38
        $this->addressLine1 = $addressLine1;
39
40
        return $this;
41
    }
42
43
    public function getAddressLine2(): ?string
44
    {
45
        return $this->addressLine2;
46
    }
47
48
    public function setAddressLine2(string $addressLine2): self
49
    {
50
        $this->addressLine2 = $addressLine2;
51
52
        return $this;
53
    }
54
55
    public function getFullAddress() : string
56
    {
57
        $address = $this->getName();
58
59
        if ($this->getAddressLine1()) {
60
            $address .= "\n" . $this->getAddressLine1();
61
        }
62
63
        $address .= sprintf("\n%s-%s", $this->getCountry(), $this->getAddressLine2());
64
65
        return $address;
66
    }
67
68
    public function getQrCodeData() : array
69
    {
70
        return [
71
            $this->getAddressLine2() ? self::ADDRESS_TYPE : '',
72
            $this->getName(),
73
            $this->getAddressLine1(),
74
            $this->getAddressLine2(),
75
            '',
76
            '',
77
            $this->getCountry()
78
        ];
79
    }
80
81
    public static function loadValidatorMetadata(ClassMetadata $metadata)
82
    {
83
        $metadata->addPropertyConstraints('addressLine1', [
84
            new Assert\Length([
85
                'max' => 70
86
            ])
87
        ]);
88
89
        $metadata->addPropertyConstraints('addressLine2', [
90
            new Assert\NotBlank(),
91
            new Assert\Length([
92
                'max' => 70
93
            ])
94
        ]);
95
    }
96
}