Completed
Push — master ( 72a295...27f914 )
by Dieter
07:24
created

Base::analyzePriceXplorerExtremeSearchResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 1
crap 1
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\ResponseHandler;
24
25
use Amadeus\Client\Exception;
26
use Amadeus\Client\ResponseHandler\Air\HandlerRetrieveSeatMap;
27
use Amadeus\Client\Result;
28
use Amadeus\Client\Session\Handler\SendResult;
29
30
/**
31
 * Default Response Handler
32
 *
33
 * Analyses the responses received from the Amadeus WS server and checks for error messages.
34
 * If errors are found, the error information will be extracted and the response status will be changed
35
 * accordingly.
36
 *
37
 * @package Amadeus\Client\ResponseHandler
38
 * @author Dieter Devlieghere <[email protected]>
39
 */
40
class Base extends BaseUtils
41
{
42
    /**
43
     * Analyze the response from the server and throw an exception when an error has been detected.
44
     *
45
     * @param SendResult $sendResult The Send Result from the Session Handler
46
     * @param string $messageName The message that was called
47
     *
48
     * @throws Exception
49
     * @throws \RuntimeException
50
     * @return Result
51
     */
52 80
    public function analyzeResponse($sendResult, $messageName)
53
    {
54 80
        $methodName = 'analyze'.str_replace('_', '', ucfirst($messageName)).'Response';
55
56 80
        if (!empty($sendResult->exception)) {
57 2
            return $this->makeResultForException($sendResult);
58 78
        } elseif (method_exists($this, $methodName)) {
59 77
            return $this->$methodName(
60
                $sendResult
61 77
            );
62
        } else {
63 1
            return new Result($sendResult, Result::STATUS_UNKNOWN);
64
        }
65
    }
66
67
    /**
68
     * Analysing a Security_Authenticate
69
     *
70
     * @param SendResult $response Security_Authenticate result
71
     * @return Result
72
     */
73 2
    protected function analyzeSecurityAuthenticateResponse($response)
74
    {
75 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
76
    }
77
78
    /**
79
     * Analysing a Security_Authenticate
80
     *
81
     * @param SendResult $response Security_Authenticate result
82
     * @return Result
83
     */
84 2
    protected function analyzeSecuritySignOutResponse($response)
85
    {
86 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
87
    }
88
89
    /**
90
     * Unknown response for Command_Cryptic because you need to analyse the cryptic response yourself
91
     *
92
     * @param SendResult $response
93
     * @return Result
94
     */
95 1
    protected function analyzeCommandCrypticResponse($response)
96
    {
97 1
        $ccResult = new Result($response, Result::STATUS_UNKNOWN);
98 1
        $ccResult->messages[] = new Result\NotOk(
99 1
            0,
100
            "Response handling not supported for cryptic entries"
101 1
        );
102
103 1
        return $ccResult;
104
    }
105
106 1 View Code Duplication
    protected function analyzeAirMultiAvailabilityResponse($response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108 1
        $analyzeResponse = new Result($response);
109
110 1
        $message = null;
111
112 1
        $domXpath = $this->makeDomXpath($response->responseXml);
113
114 1
        $codeNode = $domXpath->query("//m:errorOrWarningSection/m:errorOrWarningInfo//m:code")->item(0);
115 1
        if ($codeNode instanceof \DOMNode) {
116 1
            $analyzeResponse->status = Result::STATUS_ERROR;
117
118 1
            $categoryNode = $domXpath->query("//m:errorOrWarningSection/m:errorOrWarningInfo//m:type")->item(0);
119 1
            if ($categoryNode instanceof \DOMNode) {
120 1
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
121 1
            }
122
123 1
            $messageNodes = $domXpath->query('//m:errorOrWarningSection/m:textInformation/m:freeText');
124 1
            if ($messageNodes->length > 0) {
125 1
                $message = $this->makeMessageFromMessagesNodeList($messageNodes);
126 1
            }
127 1
            $analyzeResponse->messages [] = new Result\NotOk($codeNode->nodeValue, $message);
128 1
        }
129
130 1
        return $analyzeResponse;
131
    }
132
133 2
    protected function analyzeAirSellFromRecommendationResponse($response)
134
    {
135 2
        $analyzeResponse = new Result($response);
136
137
        $errMsgMap = [
138 2
            "288" => "UNABLE TO SATISFY, NEED CONFIRMED FLIGHT STATUS",
139
            "390" => "UNABLE TO REFORMAT"
140 2
        ];
141
142 2
        $domXpath = $this->makeDomXpath($response->responseXml);
143
144 2
        $codeNode = $domXpath->query("//m:errorSegment/m:errorDetails/m:errorCode")->item(0);
145 2
        if ($codeNode instanceof \DOMNode) {
146 2
            $analyzeResponse->status = Result::STATUS_ERROR;
147
148 2
            $categoryNode = $domXpath->query("//m:errorSegment/m:errorDetails/m:errorCategory")->item(0);
149 2
            if ($categoryNode instanceof \DOMNode) {
150 2
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
151 2
            }
152
153 2
            $message = (array_key_exists($codeNode->nodeValue, $errMsgMap)) ?
154 2
                $errMsgMap[$codeNode->nodeValue] : 'UNKNOWN ERROR';
155
156 2
            $analyzeResponse->messages [] = new Result\NotOk($codeNode->nodeValue, $message);
157 2
        }
158
159 2
        return $analyzeResponse;
160
    }
161
162
    /**
163
     * @param SendResult $response
164
     * @return Result
165
     */
166 1
    protected function analyzeAirFlightInfoResponse($response)
167
    {
168 1
        $analyzeResponse = new Result($response);
169
170 1
        $code = null;
171 1
        $message = null;
172
173 1
        $domXpath = $this->makeDomXpath($response->responseXml);
174
175 1
        $categoryNodes = $domXpath->query('//m:responseError/m:errorInfo/m:errorDetails/m:errorCategory');
176 1
        if ($categoryNodes->length > 0) {
177 1
            $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNodes->item(0)->nodeValue);
178 1
        }
179
180 1
        $codeNodes = $domXpath->query('//m:responseError/m:errorInfo/m:errorDetails/m:errorCode');
181 1
        if ($codeNodes->length > 0) {
182 1
            $code = $codeNodes->item(0)->nodeValue;
183 1
        }
184
185 1
        $messageNodes = $domXpath->query('//m:responseError/m:interactiveFreeText/m:freeText');
186 1
        if ($messageNodes->length > 0) {
187 1
            $message = $this->makeMessageFromMessagesNodeList($messageNodes);
188 1
        }
189
190 1
        if (!is_null($message) && !is_null($code)) {
191 1
            $analyzeResponse->messages[] = new Result\NotOk($code, $message);
192 1
        }
193
194 1
        return $analyzeResponse;
195
    }
196
197
    /**
198
     * @param SendResult $response
199
     * @return Result
200
     */
201 6
    protected function analyzeAirRetrieveSeatMapResponse($response)
202
    {
203 6
        $analyzeResponse = new Result($response);
204
205 6
        $domXpath = $this->makeDomXpath($response->responseXml);
206
207 6
        $errorCodeNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:code');
208 6 View Code Duplication
        if ($errorCodeNode->length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209 3
            $analyzeResponse->status = Result::STATUS_ERROR;
210
211 3
            $errCode = $errorCodeNode->item(0)->nodeValue;
212 3
            $level = null;
213
214 3
            $errorLevelNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:processingLevel');
215 3
            if ($errorLevelNode->length > 0) {
216 3
                $level = HandlerRetrieveSeatMap::decodeProcessingLevel($errorLevelNode->item(0)->nodeValue);
217 3
            }
218
219 3
            $errorDescNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:description');
220 3
            if ($errorDescNode->length > 0) {
221 1
                $errDesc = $errorDescNode->item(0)->nodeValue;
222 1
            } else {
223 2
                $errDesc = HandlerRetrieveSeatMap::findMessage($errCode);
224
            }
225
226 3
            $analyzeResponse->messages[] = new Result\NotOk(
227 3
                $errCode,
228 3
                $errDesc,
229
                $level
230 3
            );
231 3
        }
232
233 6
        $codeNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:number');
234 6 View Code Duplication
        if ($codeNode->length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
235 2
            $analyzeResponse->status = Result::STATUS_WARN;
236
237 2
            $warnCode = $codeNode->item(0)->nodeValue;
238 2
            $level = null;
239
240 2
            $levelNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:processingLevel');
241 2
            if ($levelNode->length > 0) {
242 2
                $level = HandlerRetrieveSeatMap::decodeProcessingLevel($levelNode->item(0)->nodeValue);
243 2
            }
244
245 2
            $descNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:description');
246 2
            if ($descNode->length > 0) {
247 1
                $warnDesc = $descNode->item(0)->nodeValue;
248 1
            } else {
249 1
                $warnDesc = HandlerRetrieveSeatMap::findMessage($warnCode);
250
            }
251
252 2
            $analyzeResponse->messages[] = new Result\NotOk(
253 2
                $warnCode,
254 2
                $warnDesc,
255
                $level
256 2
            );
257 2
        }
258
259 6
        return $analyzeResponse;
260
    }
261
262
    /**
263
     * Analysing a PNR_Retrieve response
264
     *
265
     * @param SendResult $response PNR_Retrieve result
266
     * @return Result
267
     */
268 1
    protected function analyzePnrRetrieveResponse($response)
269
    {
270 1
        return $this->analyzePnrReply($response);
271
    }
272
273
    /**
274
     * @param SendResult $response PNR_AddMultiElements result
275
     * @return Result
276
     */
277 4
    protected function analyzePnrAddMultiElementsResponse($response)
278
    {
279 4
        return $this->analyzePnrReply($response);
280
    }
281
282
    /**
283
     * @param SendResult $response PNR_Cancel result
284
     * @return Result
285
     */
286 1
    protected function analyzePnrCancelResponse($response)
287
    {
288 1
        return $this->analyzePnrReply($response);
289
    }
290
291
    /**
292
     * @param SendResult $response Pnr_RetrieveAndDisplay response
293
     * @return Result
294
     * @throws Exception
295
     */
296 2
    protected function analyzePnrRetrieveAndDisplayResponse($response)
297
    {
298 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
299
    }
300
301
    /**
302
     * Analysing a PNR_TransferOwnershipReply
303
     *
304
     * @param SendResult $response PNR_TransferOwnership response
305
     * @return Result
306
     * @throws Exception
307
     */
308 2
    protected function analyzePNRTransferOwnershipResponse($response)
309
    {
310 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
311
    }
312
313
    /**
314
     * Analysing a PNR_NameChangeReply
315
     *
316
     * @param SendResult $response PNR_NameChange response
317
     * @return Result
318
     * @throws Exception
319
     */
320 2
    protected function analyzePNRNameChangeResponse($response)
321
    {
322 2
        $analyzeResponse = new Result($response);
323
324 2
        $domXpath = $this->makeDomXpath($response->responseXml);
325
326 2
        $qPassErrors = "//m:passengerErrorInEnhancedData//m:errorDetails/m:errorCode";
327 2
        $qPassErrorCat = "//m:passengerErrorInEnhancedData//m:errorDetails/m:errorCategory";
328 2
        $qPassErrorMsg = "//m:passengerErrorInEnhancedData//m:freeText";
329
330
331 2
        $errorCodeNodeList = $domXpath->query($qPassErrors);
332
333 2
        if ($errorCodeNodeList->length > 0) {
334 1
            $analyzeResponse->status = Result::STATUS_ERROR;
335
336 1
            $errorCatNode = $domXpath->query($qPassErrorCat)->item(0);
337 1
            if ($errorCatNode instanceof \DOMNode) {
338 1
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
339 1
            }
340
341 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
342 1
            $errorTextNodeList = $domXpath->query($qPassErrorMsg);
343 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
344
345 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'passenger');
346 1
        }
347
348 2
        if (empty($analyzeResponse->messages) && $analyzeResponse->status === Result::STATUS_OK) {
349 1
            $analyzeResponse = $this->analyzeSimpleResponseErrorCodeAndMessage($response);
350 1
        }
351
352 2
        return $analyzeResponse;
353
    }
354
355
    /**
356
     * Analysing a PNR_DisplayHistoryReply
357
     *
358
     * @param SendResult $response PNR_DisplayHistoryReply result
359
     * @return Result
360
     * @throws Exception
361
     */
362 2
    protected function analyzePnrDisplayHistoryResponse($response)
363
    {
364 2
        $analyzeResponse = new Result($response);
365
366 2
        $domXpath = $this->makeDomXpath($response->responseXml);
367
368 2
        $queryAllErrorCodes = "//m:generalErrorGroup//m:errorNumber/m:errorDetails/m:errorCode";
369 2
        $queryAllErrorMsg = "//m:generalErrorGroup/m:genrealErrorText/m:freeText";
370
371 2
        $errorCodeNodeList = $domXpath->query($queryAllErrorCodes);
372
373 2 View Code Duplication
        if ($errorCodeNodeList->length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
374 1
            $analyzeResponse->status = Result::STATUS_ERROR;
375
376 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
377 1
            $errorTextNodeList = $domXpath->query($queryAllErrorMsg);
378 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
379
380 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message));
381 1
        }
382
383 2
        return $analyzeResponse;
384
    }
385
386
    /**
387
     * @param SendResult $response Queue_RemoveItem response
388
     * @return Result
389
     * @throws Exception
390
     */
391 1
    protected function analyzeQueueRemoveItemResponse($response)
392
    {
393 1
        return $this->analyzeGenericQueueResponse($response);
394
    }
395
396
    /**
397
     * @param SendResult $response Queue_MoveItem response
398
     * @return Result
399
     * @throws Exception
400
     */
401 2
    protected function analyzeQueueMoveItemResponse($response)
402
    {
403 2
        return $this->analyzeGenericQueueResponse($response);
404
    }
405
406
    /**
407
     * @param SendResult $response Queue_PlacePNR response
408
     * @return Result
409
     * @throws Exception
410
     */
411 1
    protected function analyzeQueuePlacePNRResponse($response)
412
    {
413 1
        return $this->analyzeGenericQueueResponse($response);
414
    }
415
416
    /**
417
     * @param SendResult $response Queue_List result
418
     * @return Result
419
     * @throws Exception
420
     */
421 2
    protected function analyzeQueueListResponse($response)
422
    {
423 2
        return $this->analyzeGenericQueueResponse($response);
424
    }
425
426
    /**
427
     * Analyze a generic Queue response
428
     *
429
     * @param SendResult $response Queue_*Reply result
430
     * @return Result
431
     * @throws Exception
432
     */
433 6
    protected function analyzeGenericQueueResponse($response)
434
    {
435 6
        $analysisResponse = new Result($response);
436
437 6
        $domDoc = $this->loadDomDocument($response->responseXml);
438
439 6
        $errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0);
440
441 6
        if (!is_null($errorCodeNode)) {
442 3
            $analysisResponse->status = Result::STATUS_WARN;
443
444 3
            $errorCode = $errorCodeNode->nodeValue;
445 3
            $errorMessage = $this->getErrorTextFromQueueErrorCode($errorCode);
446
447 3
            $analysisResponse->messages[] = new Result\NotOk($errorCode, $errorMessage);
448 3
        }
449
450 6
        return $analysisResponse;
451
    }
452
453
454
    /**
455
     * @param SendResult $response Fare_PricePNRWithBookingClass result
456
     * @return Result
457
     * @throws Exception
458
     */
459 8 View Code Duplication
    protected function analyzeFarePricePNRWithBookingClassResponse($response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
460
    {
461 8
        $analyzeResponse = new Result($response);
462
463 8
        $domXpath = $this->makeDomXpath($response->responseXml);
464
465 7
        $queryErrorCode = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
466 7
        $queryErrorCategory = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory";
467 7
        $queryErrorMsg = "//m:applicationError/m:errorWarningDescription/m:freeText";
468
469 7
        $errorCodeNodeList = $domXpath->query($queryErrorCode);
470
471 7
        if ($errorCodeNodeList->length > 0) {
472 4
            $analyzeResponse->status = Result::STATUS_ERROR;
473
474 4
            $errorCatNode = $domXpath->query($queryErrorCategory)->item(0);
475 4
            if ($errorCatNode instanceof \DOMNode) {
476 4
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
477 4
            }
478
479 4
            $analyzeResponse->messages[] = new Result\NotOk(
480 4
                $errorCodeNodeList->item(0)->nodeValue,
481 4
                $this->makeMessageFromMessagesNodeList(
482 4
                    $domXpath->query($queryErrorMsg)
483 4
                )
484 4
            );
485 4
        }
486
487 7
        return $analyzeResponse;
488
    }
489
490
    /**
491
     * @param SendResult $response Fare_PricePNRWithLowerFares result
492
     * @return Result
493
     * @throws Exception
494
     */
495 2
    protected function analyzeFarePricePNRWithLowerFaresResponse($response)
496
    {
497 2
        return $this->analyzeFarePricePNRWithBookingClassResponse($response);
498
    }
499
500
    /**
501
     * @param SendResult $response Fare_PricePNRWithLowestFare result
502
     * @return Result
503
     * @throws Exception
504
     */
505 2
    protected function analyzeFarePricePNRWithLowestFareResponse($response)
506
    {
507 2
        return $this->analyzeFarePricePNRWithBookingClassResponse($response);
508
    }
509
510
    /**
511
     * @param SendResult $response
512
     * @return Result
513
     */
514 1
    protected function analyzeFareMasterPricerCalendarResponse($response)
515
    {
516 1
        return $this->analyzeFareMasterPricerTravelBoardSearchResponse($response);
517
    }
518
519
    /**
520
     * @param SendResult $response
521
     * @return Result
522
     */
523 2
    protected function analyzeFareMasterPricerTravelBoardSearchResponse($response)
524
    {
525 2
        $analyzeResponse = new Result($response);
526
527 2
        $domXpath = $this->makeDomXpath($response->responseXml);
528
529 2
        $queryErrCode = "//m:applicationError//m:applicationErrorDetail/m:error";
530 2
        $queryErrMsg = "//m:errorMessageText/m:description";
531
532 2
        $codeNode = $domXpath->query($queryErrCode)->item(0);
533
534 2
        if ($codeNode instanceof \DOMNode) {
535 2
            $analyzeResponse->status = Result::STATUS_ERROR;
536
537 2
            $errMsg = '';
538 2
            $errMsgNode = $domXpath->query($queryErrMsg)->item(0);
539 2
            if ($errMsgNode instanceof \DOMNode) {
540 2
                $errMsg = $errMsgNode->nodeValue;
541 2
            }
542
543 2
            $analyzeResponse->messages[] = new Result\NotOk(
544 2
                $codeNode->nodeValue,
545
                $errMsg
546 2
            );
547 2
        }
548
549 2
        return $analyzeResponse;
550
    }
551
552
    /**
553
     * @param SendResult $response
554
     * @return Result
555
     */
556 1
    protected function analyzeFareConvertCurrencyResponse($response)
557
    {
558 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
559
    }
560
561
    /**
562
     * @param SendResult $response
563
     * @return Result
564
     */
565 1
    protected function analyzeFareCheckRulesResponse($response)
566
    {
567 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
568
    }
569
570
    /**
571
     * @param SendResult $response
572
     * @return Result
573
     */
574 2
    protected function analyzeFareInformativePricingWithoutPNRResponse($response)
575
    {
576 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
577
    }
578
579
    /**
580
     * @param SendResult $response
581
     * @return Result
582
     */
583 2
    protected function analyzeFareInformativeBestPricingWithoutPNRResponse($response)
584
    {
585 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
586
    }
587
588
    /**
589
     * DocIssuance_IssueTicket
590
     *
591
     * @param SendResult $response
592
     * @return Result
593
     */
594 2
    protected function analyzeDocIssuanceIssueTicketResponse($response)
595
    {
596 2
        return $this->analyzeSimpleResponseErrorCodeAndMessageStatusCode($response);
597
    }
598
599
    /**
600
     * DocIssuance_IssueMiscellaneousDocuments
601
     *
602
     * @param SendResult $response
603
     * @return Result
604
     */
605 1
    protected function analyzeDocIssuanceIssueMiscellaneousDocumentsResponse($response)
606
    {
607 1
        return $this->analyzeSimpleResponseErrorCodeAndMessageStatusCode($response);
608
    }
609
610
    /**
611
     * @param SendResult $response Ticket_DeleteTST result
612
     * @return Result
613
     */
614 1
    protected function analyzeTicketDisplayTSTResponse($response)
615
    {
616 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
617
    }
618
619
    /**
620
     * @param SendResult $response Ticket_DeleteTST result
621
     * @return Result
622
     */
623 1
    protected function analyzeTicketDeleteTSTResponse($response)
624
    {
625 1
        return $this->analyzeTicketCreateTSTFromPricingResponse($response);
626
    }
627
628
    /**
629
     * @param SendResult $response Ticket_DeleteTSMP result
630
     * @return Result
631
     */
632 1
    protected function analyzeTicketDeleteTSMPResponse($response)
633
    {
634 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
635
    }
636
637
    /**
638
     * @param SendResult $response Ticket_CreateTSTFromPricing result
639
     * @return Result
640
     */
641 3 View Code Duplication
    protected function analyzeTicketCreateTSTFromPricingResponse($response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
642
    {
643 3
        $analyzeResponse = new Result($response);
644
645 3
        $domDoc = $this->loadDomDocument($response->responseXml);
646
647 3
        $errorCodeNode = $domDoc->getElementsByTagName("applicationErrorCode")->item(0);
648
649 3
        if (!is_null($errorCodeNode)) {
650 3
            $analyzeResponse->status = Result::STATUS_ERROR;
651
652 3
            $errorCatNode = $domDoc->getElementsByTagName("codeListQualifier")->item(0);
653 3
            if ($errorCatNode instanceof \DOMNode) {
654 3
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
655 3
            }
656
657 3
            $errorCode = $errorCodeNode->nodeValue;
658 3
            $errorTextNodeList = $domDoc->getElementsByTagName("errorFreeText");
659
660 3
            $analyzeResponse->messages[] = new Result\NotOk(
661 3
                $errorCode,
662 3
                $this->makeMessageFromMessagesNodeList($errorTextNodeList)
663 3
            );
664 3
        }
665
666 3
        return $analyzeResponse;
667
    }
668
669
    /**
670
     * @param SendResult $response Ticket_CreateTSMFromPricing result
671
     * @return Result
672
     */
673 1
    protected function analyzeTicketCreateTSMFromPricingResponse($response)
674
    {
675 1
        return $this->analyzeTicketCreateTSTFromPricingResponse($response);
676
    }
677
678
    /**
679
     * @param SendResult $response
680
     * @return Result
681
     */
682 2
    protected function analyzeOfferConfirmCarOfferResponse($response)
683
    {
684 2
        return $this->analyzeGenericOfferResponse($response);
685
    }
686
687
    /**
688
     * @param SendResult $response
689
     * @return Result
690
     */
691 2
    protected function analyzeOfferConfirmHotelOfferResponse($response)
692
    {
693 2
        $analyzeResponse = new Result($response);
694
695 2
        $domXpath = $this->makeDomXpath($response->responseXml);
696
697 2
        $codeNode = $domXpath->query("//m:errorDetails/m:errorCode")->item(0);
698 2
        if ($codeNode instanceof \DOMNode) {
699 1
            $analyzeResponse->status = Result::STATUS_ERROR;
700
701 1
            $categoryNode = $domXpath->query("//m:errorDetails/m:errorCategory")->item(0);
702 1
            if ($categoryNode instanceof \DOMNode) {
703 1
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
704 1
            }
705
706 1
            $msgNode = $domXpath->query('//m:errorDescription/m:freeText')->item(0);
707
708 1
            $analyzeResponse->messages[] = new Result\NotOk(
709 1
                $codeNode->nodeValue,
710 1
                trim($msgNode->nodeValue)
711 1
            );
712 1
        }
713
714 2
        return $analyzeResponse;
715
    }
716
717
    /**
718
     * Offer_ConfirmAirOffer
719
     *
720
     * @param SendResult $response
721
     * @return Result
722
     */
723 2
    protected function analyzeOfferConfirmAirOfferResponse($response)
724
    {
725 2
        return $this->analyzeGenericOfferResponse($response);
726
    }
727
728
    /**
729
     * Offer_VerifyOffer
730
     *
731
     * @param SendResult $response
732
     * @return Result
733
     */
734 2
    protected function analyzeOfferVerifyOfferResponse($response)
735
    {
736 2
        return $this->analyzeGenericOfferResponse($response);
737
    }
738
739
    /**
740
     * Offer_CreateOffer
741
     *
742
     * @param SendResult $response
743
     * @return Result
744
     */
745 2
    protected function analyzeOfferCreateOfferResponse($response)
746
    {
747 2
        return $this->analyzeGenericOfferResponse($response);
748
    }
749
750
    /**
751
     * @param SendResult $response
752
     * @return Result
753
     */
754 2
    protected function analyzeMiniRuleGetFromPricingRecResponse($response)
755
    {
756 2
        $analyzeResponse = new Result($response);
757
758 2
        $domXpath = $this->makeDomXpath($response->responseXml);
759
760 2
        $statusNode = $domXpath->query('//m:responseDetails/m:statusCode')->item(0);
761 2
        if ($statusNode instanceof \DOMNode) {
762 2
            $code = $statusNode->nodeValue;
763
764 2
            if ($code !== 'O') {
765 2
                $categoryNode = $domXpath->query(
766
                    '//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory'
767 2
                )->item(0);
768 2
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
769
770 2
                $codeNode = $domXpath->query('//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode')->item(0);
771 2
                $msgNode = $domXpath->query('//m:errorWarningDescription/m:freeText')->item(0);
772
773 2
                if ($codeNode instanceof \DOMNode && $msgNode instanceof \DOMNode) {
774 2
                    $analyzeResponse->messages[] = new Result\NotOk(
775 2
                        $codeNode->nodeValue,
776 2
                        $msgNode->nodeValue
777 2
                    );
778 2
                }
779 2
            }
780 2
        }
781
782 2
        return $analyzeResponse;
783
    }
784
785
    /**
786
     * @param SendResult $response
787
     * @return Result
788
     */
789 1
    protected function analyzeMiniRuleGetFromPricingResponse($response)
790
    {
791 1
        return $this->analyzeMiniRuleGetFromPricingRecResponse($response);
792
    }
793
794
    /**
795
     * @param SendResult $response
796
     * @return Result
797
     */
798 1
    protected function analyzeInfoEncodeDecodeCityResponse($response)
799
    {
800 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
801
    }
802
803
    /**
804
     * @param SendResult $response
805
     * @return Result
806
     */
807 1
    protected function analyzePriceXplorerExtremeSearchResponse($response)
808
    {
809 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
810
    }
811
812
    /**
813
     * @param SendResult $response
814
     * @return Result
815
     */
816 1
    protected function analyzePointOfRefSearchResponse($response)
817
    {
818
        //TODO verify the actual error XML - documentation is lacking.
819 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
820
    }
821
822
    /**
823
     * @param SendResult $response
824
     * @return Result
825
     */
826 1
    protected function analyzeSalesReportsDisplayQueryReportResponse($response)
827
    {
828 1
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
829
    }
830
831
    /**
832
     * @param SendResult $response
833
     * @return Result
834
     */
835 2
    protected function analyzeServiceIntegratedPricingResponse($response)
836
    {
837 2
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
838
    }
839
}
840