Test Failed
Pull Request — master (#6)
by Laurens
01:35
created

BoardingPassbook   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook;
6
7
use LauLamanApps\ApplePassbook\Exception\MissingRequiredDataException;
8
use LauLamanApps\ApplePassbook\MetaData\BoardingPass\TransitType;
9
10
class BoardingPassbook extends Passbook
11
{
12
    protected const TYPE = 'boardingPass';
13
14
    private TransitType $transitType;
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...
15
16
    public function __construct(string $serialNumber, TransitType $transitType = null)
17
    {
18
        parent::__construct($serialNumber);
19 2
20
        if ($transitType) {
21 2
            $this->setTransitType($transitType);
22 2
        }
23
    }
24
25
26
    public function setTransitType(TransitType $transitType): void
27 7
    {
28
        $this->transitType = $transitType;
29 7
    }
30
31 3
    /**
32 1
     * @throws MissingRequiredDataException
33
     */
34 2
    public function validate(): void
35
    {
36
        parent::validate();
37 3
38
        if (!isset($this->transitType)) {
39 3
            throw new MissingRequiredDataException('Please specify the TransitType before requesting the manifest data.');
40 2
        }
41
    }
42 2
43
    /**
44
     * @return array<int|string, mixed>
45
     */
46
    public function getData(): array
47
    {
48
        $data = parent::getData();
49
        $data[static::TYPE]['transitType'] = (string) $this->transitType->getValue();
50
51
        return $data;
52
    }
53
}
54