Test Failed
Pull Request — master (#6)
by Laurens
02:27
created

Barcode   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 64
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook\MetaData;
6
7
use LauLamanApps\ApplePassbook\Style\BarcodeFormat;
8
use LogicException;
9
10
class Barcode
11
{
12
    private string $altText;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
13
    private BarcodeFormat $format;
14
    private string $message;
15
    private string $messageEncoding = 'iso-8859-1';
16
17 4
    public function __construct(?BarcodeFormat $format = null, ?string $message = null, ?string $altText = null)
18
    {
19 4
        $this->format = $format ?? BarcodeFormat::pdf417();
20
21 4
        if ($message) {
22 3
            $this->message = $message;
23
        }
24
25 4
        if ($altText){
26 1
            $this->altText = $altText;
27
        }
28 4
    }
29
30 1
    public function setFormat(BarcodeFormat $format): void
31
    {
32 1
        $this->format = $format;
33 1
    }
34
35 1
    public function setMessage(string $message): void
36
    {
37 1
        $this->message = $message;
38 1
    }
39
40 1
    public function setAltText(string $altText): void
41
    {
42 1
        $this->altText = $altText;
43 1
    }
44
45 1
    public function setMessageEncoding(string $messageEncoding): void
46
    {
47 1
        $this->messageEncoding = $messageEncoding;
48 1
    }
49
50
    /**
51
     * @return array<string, string>
52
     */
53 4
    public function toArray(): array
54
    {
55 4
        $this->validate();
56
57
        $data = [
58 4
            'format' => (string) $this->format->getValue(),
59 4
            'message' => $this->message,
60 4
            'messageEncoding' => $this->messageEncoding,
61
        ];
62
63 4
        if (isset($this->altText)) {
64 1
            $data['altText'] = $this->altText;
65
        }
66
67 4
        return $data;
68
    }
69
70 4
    private function validate(): void
71
    {
72 4
        if (!isset($this->message)) {
73
            throw new LogicException('no message specified');
74
        }
75 4
    }
76
}
77