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

AlternativeScheme   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A loadValidatorMetadata() 0 6 1
A getQrCodeData() 0 4 1
A setParameter() 0 5 1
A getParameter() 0 3 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
class AlternativeScheme implements QrCodeableInterface, SelfValidatableInterface
12
{
13
    use SelfValidatableTrait;
14
15
    /**
16
     * Parameter character chain of the alternative scheme
17
     * 
18
     * @var string
19
     */
20
    private $parameter;
21
22
    public function getParameter(): ?string
23
    {
24
        return $this->parameter;
25
    }
26
27
    public function setParameter(string $parameter) : self
28
    {
29
        $this->parameter = $parameter;
30
31
        return $this;
32
    }
33
34
    public function getQrCodeData() : array
35
    {
36
        return [
37
            $this->getParameter()
38
        ];
39
    }
40
41
    /**
42
     * Note that no real-life alternative schemes yet exist. Therefore validation is kept simple yet.
43
     * @link https://www.paymentstandards.ch/en/home/softwarepartner/qr-bill/alternative-schemes.html
44
     */
45
    public static function loadValidatorMetadata(ClassMetadataInterface $metadata) : void
46
    {
47
        $metadata->addPropertyConstraints('parameter', [
48
            new Assert\NotBlank(),
49
            new Assert\Length([
50
                'max' => 100
51
            ])
52
        ]);
53
    }
54
}