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

AbstractAddress   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setCountry() 0 5 1
A getName() 0 3 1
A setName() 0 5 1
A getCountry() 0 3 1
A loadValidatorMetadata() 0 12 1
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
}