Completed
Branch develop (8166a6)
by Romain
01:52
created

PassengerSegmentInfo::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
namespace Kerox\Messenger\Model\Message\Attachment\Template\Airline;
3
4
use Kerox\Messenger\ValidatorTrait;
5
6
class PassengerSegmentInfo implements \JsonSerializable
7
{
8
9
    use ValidatorTrait;
10
11
    /**
12
     * @var string
13
     */
14
    protected $segmentId;
15
16
    /**
17
     * @var string
18
     */
19
    protected $passengerId;
20
21
    /**
22
     * @var string
23
     */
24
    protected $seat;
25
26
    /**
27
     * @var string
28
     */
29
    protected $seatType;
30
31
    /**
32
     * @var array
33
     */
34
    protected $productInfo = [];
35
36
    /**
37
     * PassengerSegmentInfo constructor.
38
     *
39
     * @param string $segmentId
40
     * @param string $passengerId
41
     * @param string $seat
42
     * @param string $seatType
43
     */
44
    public function __construct(string $segmentId, string $passengerId, string $seat, string $seatType)
45
    {
46
        $this->segmentId = $segmentId;
47
        $this->passengerId = $passengerId;
48
        $this->seat = $seat;
49
        $this->seatType = $seatType;
50
    }
51
52
    /**
53
     * @param string $title
54
     * @param string $value
55
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Airline\PassengerSegmentInfo
56
     * @internal param array $productInfo
57
     */
58
    public function addProductInfo(string $title, string $value): PassengerSegmentInfo
59
    {
60
        $this->isValidArray($this->productInfo, 4);
61
        $this->productInfo[] = [
62
            'title' => $title,
63
            'value' => $value,
64
        ];
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return array
71
     */
72
    public function jsonSerialize(): array
73
    {
74
        $json = [
75
            'segment_id' => $this->segmentId,
76
            'passenger_id' => $this->passengerId,
77
            'seat' => $this->seat,
78
            'seat_type' => $this->seatType,
79
            'product_info' => $this->productInfo,
80
        ];
81
82
        return array_filter($json);
83
    }
84
}
85