FlightSchedule::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
use Kerox\Messenger\Helper\ValidatorTrait;
8
9
class FlightSchedule implements \JsonSerializable
10
{
11
    use ValidatorTrait;
12
13
    /**
14
     * @var string|null
15
     */
16
    protected $boardingTime;
17
18
    /**
19
     * @var string
20
     */
21
    protected $departureTime;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $arrivalTime;
27
28
    /**
29
     * FlightSchedule constructor.
30
     *
31
     * @throws \Kerox\Messenger\Exception\MessengerException
32
     */
33 10
    public function __construct(string $departureTime)
34
    {
35 10
        $this->isValidDateTime($departureTime);
36
37 10
        $this->departureTime = $departureTime;
38 10
    }
39
40
    /**
41
     * @throws \Kerox\Messenger\Exception\MessengerException
42
     *
43
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightSchedule
44
     */
45 10
    public static function create(string $departureTime): self
46
    {
47 10
        return new self($departureTime);
48
    }
49
50
    /**
51
     * @throws \Kerox\Messenger\Exception\MessengerException
52
     *
53
     * @return FlightSchedule
54
     */
55 3
    public function setBoardingTime(string $boardingTime): self
56
    {
57 3
        $this->isValidDateTime($boardingTime);
58
59 3
        $this->boardingTime = $boardingTime;
60
61 3
        return $this;
62
    }
63
64
    /**
65
     * @throws \Kerox\Messenger\Exception\MessengerException
66
     *
67
     * @return FlightSchedule
68
     */
69 10
    public function setArrivalTime(string $arrivalTime): self
70
    {
71 10
        $this->isValidDateTime($arrivalTime);
72
73 10
        $this->arrivalTime = $arrivalTime;
74
75 10
        return $this;
76
    }
77
78 5
    public function toArray(): array
79
    {
80
        $array = [
81 5
            'boarding_time' => $this->boardingTime,
82 5
            'departure_time' => $this->departureTime,
83 5
            'arrival_time' => $this->arrivalTime,
84
        ];
85
86 5
        return array_filter($array);
87
    }
88
89 5
    public function jsonSerialize(): array
90
    {
91 5
        return $this->toArray();
92
    }
93
}
94