PassengerInfo::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Airline;
6
7
class PassengerInfo implements \JsonSerializable
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $passengerId;
13
14
    /**
15
     * @var string|null
16
     */
17
    protected $ticketNumber;
18
19
    /**
20
     * @var string
21
     */
22
    protected $name;
23
24
    /**
25
     * PassengerInfo constructor.
26
     */
27 1
    public function __construct(string $passengerId, string $name)
28
    {
29 1
        $this->passengerId = $passengerId;
30 1
        $this->name = $name;
31 1
    }
32
33
    /**
34
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerInfo
35
     */
36 1
    public static function create(string $passengerId, string $name): self
37
    {
38 1
        return new self($passengerId, $name);
39
    }
40
41
    /**
42
     * @return PassengerInfo
43
     */
44 1
    public function setTicketNumber(string $ticketNumber): self
45
    {
46 1
        $this->ticketNumber = $ticketNumber;
47
48 1
        return $this;
49
    }
50
51 1
    public function toArray(): array
52
    {
53
        $array = [
54 1
            'passenger_id' => $this->passengerId,
55 1
            'ticket_number' => $this->ticketNumber,
56 1
            'name' => $this->name,
57
        ];
58
59 1
        return array_filter($array);
60
    }
61
62 1
    public function jsonSerialize(): array
63
    {
64 1
        return $this->toArray();
65
    }
66
}
67