Completed
Pull Request — master (#188)
by
unknown
09:32
created

makeSegmentNameForRequestElement()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 3

Importance

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

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
274 4
                    $element->companyId,
0 ignored issues
show
Bug introduced by
The property companyId does not seem to exist in Amadeus\Client\RequestOp...nr\Element\ReceivedFrom.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
275 4
                    $element->ticketNumber
0 ignored issues
show
Bug introduced by
The property ticketNumber does not seem to exist in Amadeus\Client\RequestOp...nr\Element\ReceivedFrom.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
276 2
                );
277 4
                break;
278 2
            default:
279 4
                throw new InvalidArgumentException('Element type '.$elementType.' is not supported');
280 2
        }
281 152
    }
282
283
    /**
284
     * Create the correct element identifier for a given element
285
     *
286
     * @param string $elementType
287
     * @param Element $element
288
     * @return string
289
     */
290 160
    protected function makeSegmentNameForRequestElement($elementType, $element)
291
    {
292 160
        $elementName = '';
293
294
        $sourceArray = [
295 160
            'Contact' => ElementManagementData::SEGNAME_CONTACT_ELEMENT,
296 80
            'FormOfPayment' => ElementManagementData::SEGNAME_FORM_OF_PAYMENT,
297 80
            'MiscellaneousRemark' => ElementManagementData::SEGNAME_GENERAL_REMARK,
298 80
            'ReceivedFrom' => ElementManagementData::SEGNAME_RECEIVE_FROM,
299 80
            'ServiceRequest' => ElementManagementData::SEGNAME_SPECIAL_SERVICE_REQUEST,
300 80
            'Ticketing' => ElementManagementData::SEGNAME_TICKETING_ELEMENT,
301 80
            'AccountingInfo' => ElementManagementData::SEGNAME_ACCOUNTING_INFORMATION,
302 80
            'Address' => null, // Special case - the type is a parameter.
303 80
            'FrequentFlyer' => ElementManagementData::SEGNAME_SPECIAL_SERVICE_REQUEST,
304 80
            'OtherServiceInfo' => ElementManagementData::SEGNAME_OTHER_SERVICE_INFORMATION,
305 80
            'ManualCommission' => ElementManagementData::SEGNAME_COMMISSION,
306 80
            'SeatRequest' => ElementManagementData::SEGNAME_SEAT_REQUEST,
307 80
            'TourCode' => ElementManagementData::SEGNAME_TOUR_CODE,
308
            'ManualIssuedTicket' => ElementManagementData::SEGNAME_MANUAL_DOCUMENT_REGISTRATION_WITH_ET_NUMBER
309 80
        ];
310
311 160
        if (array_key_exists($elementType, $sourceArray)) {
312 156
            $elementName = $sourceArray[$elementType];
313
314 156
            if ($elementType === 'Address') {
315
                /** @var Element\Address $element */
316 12
                $elementName = $element->type;
317 6
            }
318 78
        }
319
320 160
        return $elementName;
321
    }
322
}
323