Passed
Pull Request — master (#83)
by Romain
03:05
created

AirlineCheckInTemplate::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template;
6
7
use Kerox\Messenger\Model\Message\Attachment\Template;
8
9
class AirlineCheckInTemplate extends AbstractAirlineTemplate
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $introMessage;
15
16
    /**
17
     * @var string
18
     */
19
    protected $pnrNumber;
20
21
    /**
22
     * @var \Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo[]
23
     */
24
    protected $flightInfo;
25
26
    /**
27
     * @var string
28
     */
29
    protected $checkinUrl;
30
31
    /**
32
     * AirlineCheckIn constructor.
33
     *
34
     * @param string $introMessage
35
     * @param string $locale
36
     * @param string $pnrNumber
37
     * @param array  $flightInfo
38
     * @param string $checkinUrl
39
     *
40
     * @throws \InvalidArgumentException
41
     */
42
    public function __construct(
43
        string $introMessage,
44
        string $locale,
45
        string $pnrNumber,
46
        array $flightInfo,
47
        string $checkinUrl
48
    ) {
49
        parent::__construct($locale);
50
51
        $this->introMessage = $introMessage;
52
        $this->pnrNumber = $pnrNumber;
53
        $this->flightInfo = $flightInfo;
54
        $this->checkinUrl = $checkinUrl;
55
    }
56
57
    /**
58
     * @param string $introMessage
59
     * @param string $locale
60
     * @param string $pnrNumber
61
     * @param array  $flightInfo
62
     * @param string $checkinUrl
63
     *
64
     * @throws \InvalidArgumentException
65
     *
66
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineCheckInTemplate
67
     */
68
    public static function create(
69
        string $introMessage,
70
        string $locale,
71
        string $pnrNumber,
72
        array $flightInfo,
73
        string $checkinUrl
74
    ): self {
75
        return new self($introMessage, $locale, $pnrNumber, $flightInfo, $checkinUrl);
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function toArray(): array
82
    {
83
        $array = parent::toArray();
84
        $array += [
85
            'payload' => [
86
                'template_type' => Template::TYPE_AIRLINE_CHECKIN,
87
                'intro_message' => $this->introMessage,
88
                'locale'        => $this->locale,
89
                'theme_color'   => $this->themeColor,
90
                'pnr_number'    => $this->pnrNumber,
91
                'flight_info'   => $this->flightInfo,
92
                'checkin_url'   => $this->checkinUrl,
93
            ],
94
        ];
95
96
        return $this->arrayFilter($array);
97
    }
98
}
99