Passed
Push — master ( af1755...f0cfea )
by Manuel
01:58
created

AbstractAddress::getCountry()   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\Element;
4
5
use Sprain\SwissQrBill\DataGroup\QrCodeableInterface;
6
use Sprain\SwissQrBill\Validator\SelfValidatableInterface;
7
use Sprain\SwissQrBill\Validator\SelfValidatableTrait;
8
use Symfony\Component\Validator\Constraints as Assert;
9
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
10
11
abstract class AbstractAddress implements QrCodeableInterface, SelfValidatableInterface
12
{
13
    use SelfValidatableTrait;
14
15
    /**
16
     * Name or company
17
     *
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * Country (ISO 3166-1 alpha-2)
24
     *
25
     * @var string
26
     */
27
    private $country;
28
29
    abstract public function getFullAddress() : string;
30
31
    abstract public function getQrCodeData() : array;
32
33
    public function getName(): ?string
34
    {
35
        return $this->name;
36
    }
37
38
    public function setName(string $name) : self
39
    {
40
        $this->name = $name;
41
42
        return $this;
43
    }
44
45
    public function getCountry(): ?string
46
    {
47
        return $this->country;
48
    }
49
50
    public function setCountry(string $country) : self
51
    {
52
        $this->country = strtoupper($country);
53
54
        return $this;
55
    }
56
57
    public static function loadValidatorMetadata(ClassMetadataInterface $metadata) : void
58
    {
59
        $metadata->addPropertyConstraints('name', [
60
            new Assert\NotBlank(),
61
            new Assert\Length([
62
                'max' => 70
63
            ])
64
        ]);
65
66
        $metadata->addPropertyConstraints('country', [
67
            new Assert\NotBlank(),
68
            new Assert\Country()
69
        ]);
70
    }
71
}