Placeholder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 45
c 2
b 0
f 0
dl 0
loc 76
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 1
A getType() 0 3 1
A getWidth() 0 3 1
A getHeight() 0 3 1
A getFile() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace Sprain\SwissQrBill\PaymentPart\Output\Element;
4
5
/**
6
 * @internal
7
 */
8
final class Placeholder implements OutputElementInterface
9
{
10
    public const FILE_TYPE_SVG = 'svg';
11
    public const FILE_TYPE_PNG = 'png';
12
13
    public const PLACEHOLDER_TYPE_PAYABLE_BY = [
14
        'type' => 'placeholder_payable_by',
15
        'fileSvg' => __DIR__ . '/../../../../assets/marks_65x25mm.svg',
16
        'filePng' => __DIR__ . '/../../../../assets/marks_65x25mm.png',
17
        'width' => 65,
18
        'height' => 25
19
    ];
20
21
    public const PLACEHOLDER_TYPE_PAYABLE_BY_RECEIPT = [
22
        'type' => 'placeholder_payable_by_receipt',
23
        'fileSvg' => __DIR__ . '/../../../../assets/marks_52x20mm.svg',
24
        'filePng' => __DIR__ . '/../../../../assets/marks_52x20mm.png',
25
        'width' => 52,
26
        'height' => 20
27
    ];
28
29
    public const PLACEHOLDER_TYPE_AMOUNT = [
30
        'type' => 'placeholder_amount',
31
        'fileSvg' => __DIR__ . '/../../../../assets/marks_40x15mm.svg',
32
        'filePng' => __DIR__ . '/../../../../assets/marks_40x15mm.png',
33
        'width' => 40,
34
        'height' => 15
35
    ];
36
37
    public const PLACEHOLDER_TYPE_AMOUNT_RECEIPT = [
38
        'type' => 'placeholder_amount_receipt',
39
        'fileSvg' => __DIR__ . '/../../../../assets/marks_30x10mm.svg',
40
        'filePng' => __DIR__ . '/../../../../assets/marks_30x10mm.png',
41
        'width' => 30,
42
        'height' => 10
43
    ];
44
45
    private string $type;
46
    private string $fileSvg;
47
    private string $filePng;
48
    private int $width;
49
    private int $height;
50
51
    public static function create(array $type): self
52
    {
53
        $placeholder = new self();
54
        $placeholder->type = $type['type'];
55
        $placeholder->fileSvg = $type['fileSvg'];
56
        $placeholder->filePng = $type['filePng'];
57
        $placeholder->width = $type['width'];
58
        $placeholder->height = $type['height'];
59
60
        return $placeholder;
61
    }
62
63
    public function getType(): ?string
64
    {
65
        return $this->type;
66
    }
67
68
    public function getFile($type = self::FILE_TYPE_SVG): string
69
    {
70
        return match ($type) {
71
            self::FILE_TYPE_PNG => $this->filePng,
72
            default => $this->fileSvg,
73
        };
74
    }
75
76
    public function getWidth(): ?int
77
    {
78
        return $this->width;
79
    }
80
81
    public function getHeight(): ?int
82
    {
83
        return $this->height;
84
    }
85
}
86