BoardingPassbook::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 0
cp 0
crap 2
rs 10
c 1
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;
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