Passed
Pull Request — master (#6)
by Laurens
01:54
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 25
    public function __construct(string $serialNumber, TransitType $transitType = null)
17
    {
18 25
        parent::__construct($serialNumber);
19
20 25
        if ($transitType) {
21 1
            $this->setTransitType($transitType);
22
        }
23 25
    }
24
25
26 18
    public function setTransitType(TransitType $transitType): void
27
    {
28 18
        $this->transitType = $transitType;
29 18
    }
30
31
    /**
32
     * @throws MissingRequiredDataException
33
     */
34 22
    public function validate(): void
35
    {
36 22
        parent::validate();
37
38 18
        if (!isset($this->transitType)) {
39 1
            throw new MissingRequiredDataException('Please specify the TransitType before requesting the manifest data.');
40
        }
41 17
    }
42
43
    /**
44
     * @return array<int|string, mixed>
45
     */
46 22
    public function getData(): array
47
    {
48 22
        $data = parent::getData();
49 17
        $data[static::TYPE]['transitType'] = (string) $this->transitType->getValue();
50
51 17
        return $data;
52
    }
53
}
54