AlternativeScheme   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 41
rs 10

5 Methods

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