Completed
Push — master ( 8f168b...4b1795 )
by Dieter
09:49
created

DisplayTST::loadReferences()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 5
nop 1
crap 4
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\Ticket;
24
25
use Amadeus\Client\RequestOptions\TicketDisplayTstOptions;
26
use Amadeus\Client\Struct\BaseWsMessage;
27
28
/**
29
 * DisplayTST
30
 *
31
 * @package Amadeus\Client\Struct\Ticket
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class DisplayTST extends BaseWsMessage
35
{
36
    /**
37
     * @var DisplayMode
38
     */
39
    public $displayMode;
40
41
    /**
42
     * @var PnrLocatorData
43
     */
44
    public $pnrLocatorData;
45
46
    /**
47
     * @var ScrollingInformation
48
     */
49
    public $scrollingInformation;
50
51
    /**
52
     * @var TstReference[]
53
     */
54
    public $tstReference = [];
55
56
    /**
57
     * @var PsaInformation
58
     */
59
    public $psaInformation;
60
61
    /**
62
     * DisplayTST constructor.
63
     *
64
     * @param TicketDisplayTstOptions $params
65
     */
66 6
    public function __construct(TicketDisplayTstOptions $params)
67
    {
68 6
        $this->displayMode = new DisplayMode($params->displayMode);
69
70 6
        if ($params->displayMode === AttributeDetails::MODE_SELECTIVE) {
71 4
            $this->loadSelective($params);
72 4
        }
73 6
    }
74
75
    /**
76
     * @param TicketDisplayTstOptions $params
77
     */
78 4
    protected function loadSelective($params)
79
    {
80 4
        foreach ($params->tstNumbers as $tstNumber) {
81 1
            $this->tstReference[] = new TstReference($tstNumber);
82 4
        }
83
84 4
        $this->loadReferences($params);
85
86 4
        if ($this->checkAllNotEmpty($params->scrollingCount, $params->scrollingStart)) {
87 1
            $this->scrollingInformation = new ScrollingInformation(
88 1
                $params->scrollingCount,
89 1
                $params->scrollingStart
90 1
            );
91 1
        }
92 4
    }
93
94
    /**
95
     * Load passenger & segment references
96
     *
97
     * @param TicketDisplayTstOptions $params
98
     */
99 4
    protected function loadReferences($params)
100
    {
101 4
        if ($this->checkAnyNotEmpty($params->passengers, $params->segments)) {
102 2
            $this->psaInformation = new PsaInformation();
103
104 2
            foreach ($params->passengers as $passenger) {
105 1
                $this->psaInformation->refDetails[] = new RefDetails($passenger, RefDetails::QUAL_PASSENGER);
106 2
            }
107
108 2
            foreach ($params->segments as $segment) {
109 1
                $this->psaInformation->refDetails[] = new RefDetails($segment, RefDetails::QUAL_SEGMENT_REFERENCE);
110 2
            }
111 2
        }
112 4
    }
113
}
114