Completed
Push — master ( 529db1...994f25 )
by Dieter
06:13
created

DataElementsIndiv::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 19
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 12
nc 3
nop 2
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\Pnr\AddMultiElements;
24
25
use Amadeus\Client\RequestOptions\Pnr\Element;
26
use Amadeus\Client\Struct\InvalidArgumentException;
27
28
/**
29
 * DataElementsIndiv
30
 *
31
 * all the others segments
32
 *
33
 * @package Amadeus\Client\Struct\Pnr\AddMultiElements
34
 * @author Dieter Devlieghere <[email protected]>
35
 */
36
class DataElementsIndiv
37
{
38
    /**
39
     * To specify the PNR segments/elements references and action to apply
40
     *
41
     * @var ElementManagementData
42
     */
43
    public $elementManagementData;
44
    public $pnrSecurity;
45
    /**
46
     * @var Accounting
47
     */
48
    public $accounting;
49
    /**
50
     * To specify different kinds of remarks
51
     *
52
     * @var MiscellaneousRemark
53
     */
54
    public $miscellaneousRemark;
55
    /**
56
     * @var ServiceRequest
57
     */
58
    public $serviceRequest;
59
    public $dateAndTimeInformation;
60
    public $tourCode;
61
    /**
62
     * To specify an Amadeus PNR Ticket element
63
     *
64
     * @var TicketElement
65
     */
66
    public $ticketElement;
67
    /**
68
     * To provide free form or coded long text information.
69
     *
70
     * @var FreetextData
71
     */
72
    public $freetextData;
73
    /**
74
     * @var StructuredAddress
75
     */
76
    public $structuredAddress;
77
    public $optionElement;
78
    public $printer;
79
    public $seatGroup;
80
    public $entity;
81
    public $seatRequest;
82
    public $railSeatReferenceInformation;
83
    public $railSeatPreferences;
84
    public $fareElement;
85
    public $fareDiscount;
86
    public $manualFareDocument;
87
    public $commission;
88
    public $originalIssue;
89
    /**
90
     * To convey details describing the form of payment
91
     *
92
     * @var FormOfPayment
93
     */
94
    public $formOfPayment;
95
    /**
96
     * To convey additional details of the form of payment
97
     *
98
     * @var FopExtension[]
99
     */
100
    public $fopExtension = [];
101
    /**
102
     * To convey:
103
     * - The FOP service details
104
     * - The Corporate Security option for Remarks
105
     * - The Timestamp indicator for Remarks
106
     *
107
     * @var ServiceDetails[]
108
     */
109
    public $serviceDetails = [];
110
    public $frequentTravellerVerification;
111
    public $ticketingCarrier;
112
    public $farePrintOverride;
113
    /**
114
     * Frequent Flyer info
115
     *
116
     * @var FrequentTravellerData
117
     */
118
    public $frequentTravellerData;
119
    public $accessLevel;
120
    /**
121
     * To provide specific reference identification
122
     *
123
     * @var ReferenceForDataElement
124
     */
125
    public $referenceForDataElement;
126
127
    /**
128
     * @param Element|string $element Either an element or an element name
129
     * @param int $tattoo Unique tattoo number for this element
130
     */
131
    public function __construct($element, $tattoo)
132
    {
133
        if ($element instanceof Element) {
134
            $reflect = new \ReflectionClass($element);
135
            $elementType = $reflect->getShortName();
136
137
            $this->elementManagementData = new ElementManagementData(
138
                $this->makeSegmentNameForRequestElement($elementType, $element),
139
                $tattoo
140
            );
141
142
            $this->loadElement($element, $elementType);
143
        } elseif (is_string($element)) {
144
            $this->elementManagementData = new ElementManagementData(
145
                $element,
146
                $tattoo
147
            );
148
        }
149
    }
150
151
    /**
152
     * @param Element $element
153
     * @param string $elementType
154
     */
155
    protected function loadElement($element, $elementType)
156
    {
157
        switch ($elementType) {
158
            case 'Contact':
159
                /** @var Element\Contact $element */
160
                $this->freetextData = new FreetextData(
161
                    $element->value,
162
                    $element->type
163
                );
164
                break;
165
            case 'FormOfPayment':
166
                /** @var Element\FormOfPayment $element */
167
                $this->formOfPayment = new FormOfPayment($element->type);
168
                if ($element->type === Fop::IDENT_CREDITCARD) {
169
                    $this->formOfPayment->fop->creditCardCode = $element->creditCardType;
170
                    $this->formOfPayment->fop->accountNumber = $element->creditCardNumber;
171
                    $this->formOfPayment->fop->expiryDate = $element->creditCardExpiry;
172
                    if (!is_null($element->creditCardCvcCode)) {
173
                        $ext = new FopExtension(1);
174
                        $ext->newFopsDetails = new NewFopsDetails();
175
                        $ext->newFopsDetails->cvData = $element->creditCardCvcCode;
176
                        $this->fopExtension[] = $ext;
177
                    }
178
                } elseif ($element->type === Fop::IDENT_MISC && $element->freeText != "NONREF") {
179
                    $this->formOfPayment->fop->freetext = $element->freeText;
180
                } elseif ($element->type === Fop::IDENT_MISC && $element->freeText === "NONREF") {
181
                    $this->fopExtension[] = new FopExtension(1);
182
                } elseif ($element->type === Fop::IDENT_CHECK) {
183
                    throw new \RuntimeException("FOP CHECK NOT YET IMPLEMENTED");
184
                }
185
                break;
186
            case 'MiscellaneousRemark':
187
                /** @var Element\MiscellaneousRemark $element */
188
                $this->miscellaneousRemark = new MiscellaneousRemark(
189
                    $element->text,
190
                    $element->type,
191
                    $element->category
192
                );
193
                break;
194
            case 'ReceivedFrom':
195
                /** @var Element\ReceivedFrom $element */
196
                $this->freetextData = new FreetextData(
197
                    $element->receivedFrom,
198
                    FreetextDetail::TYPE_RECEIVE_FROM
199
                );
200
                break;
201
            case 'ServiceRequest':
202
                /** @var Element\ServiceRequest $element */
203
                $this->serviceRequest = new ServiceRequest($element);
204
                break;
205
            case 'Ticketing':
206
                /** @var Element\Ticketing $element */
207
                $this->ticketElement = new TicketElement($element);
208
                break;
209
            case 'AccountingInfo':
210
                /** @var Element\AccountingInfo $element */
211
                $this->accounting = new Accounting($element);
212
                break;
213
            case 'Address':
214
                /** @var Element\Address $element */
215
                if ($element->type === ElementManagementData::SEGNAME_ADDRESS_BILLING_UNSTRUCTURED ||
216
                    $element->type === ElementManagementData::SEGNAME_ADDRESS_MAILING_UNSTRUCTURED
217
                ) {
218
                    $this->freetextData = new FreetextData(
219
                        $element->freeText,
220
                        FreetextDetail::TYPE_MAILING_ADDRESS
221
                    );
222
                } else {
223
                    $this->structuredAddress = new StructuredAddress($element);
224
                }
225
                break;
226
            case 'FrequentFlyer':
227
                /** @var Element\FrequentFlyer $element */
228
                $this->serviceRequest = new ServiceRequest();
229
                $this->serviceRequest->ssr->type = 'FQTV';
230
                $this->serviceRequest->ssr->companyId = $element->airline;
231
                $this->frequentTravellerData = new FrequentTravellerData($element);
232
                break;
233
            case 'OtherServiceInfo':
234
                /** @var Element\OtherServiceInfo $element */
235
                $this->freetextData = new FreetextData(
236
                    $element->freeText,
237
                    FreetextDetail::TYPE_OSI_ELEMENT
238
                );
239
                $this->freetextData->freetextDetail->companyId = $element->airline;
240
                $this->freetextData->freetextDetail->subjectQualifier = FreetextDetail::QUALIFIER_LITERALTEXT;
241
                break;
242
            default:
243
                throw new InvalidArgumentException('Element type ' . $elementType . ' is not supported');
244
        }
245
    }
246
247
    /**
248
     * @param string $elementType
249
     * @param Element $element
250
     * @return string
1 ignored issue
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
251
     */
252
    protected function makeSegmentNameForRequestElement($elementType, $element)
253
    {
254
        $elementName = '';
255
256
        $sourceArray = [
257
            'Contact' => ElementManagementData::SEGNAME_CONTACT_ELEMENT,
258
            'FormOfPayment' => ElementManagementData::SEGNAME_FORM_OF_PAYMENT,
259
            'MiscellaneousRemark' => ElementManagementData::SEGNAME_GENERAL_REMARK,
260
            'ReceivedFrom' => ElementManagementData::SEGNAME_RECEIVE_FROM,
261
            'ServiceRequest' => ElementManagementData::SEGNAME_SPECIAL_SERVICE_REQUEST,
262
            'Ticketing' => ElementManagementData::SEGNAME_TICKETING_ELEMENT,
263
            'AccountingInfo' => ElementManagementData::SEGNAME_ACCOUNTING_INFORMATION,
264
            'Address' => null, // Special case - the type is a parameter.
265
            'FrequentFlyer' => ElementManagementData::SEGNAME_SPECIAL_SERVICE_REQUEST,
266
            'OtherServiceInfo' => ElementManagementData::SEGNAME_OTHER_SERVICE_INFORMATION
267
        ];
268
269
        if (array_key_exists($elementType, $sourceArray)) {
270
            $elementName = $sourceArray[$elementType];
271
272
            if ($elementType === 'Address') {
273
                /** @var Element\Address $element */
274
                $elementName = $element->type;
275
            }
276
        }
277
278
        return $elementName;
279
    }
280
}
281