BoardingPassbook   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 2
A __construct() 0 6 2
A getData() 0 6 1
A setTransitType() 0 3 1
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