Completed
Push — master ( 0fe829...fb702c )
by Dieter
08:08
created

Base::analyzeFareConvertCurrencyResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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\RetrieveSeatMap;
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
    public function analyzeResponse($sendResult, $messageName)
53
    {
54
        $methodName = 'analyze' . str_replace('_', '', ucfirst($messageName)) . 'Response';
55
56
        if (!empty($sendResult->exception)) {
57
            return $this->makeResultForException($sendResult);
58
        } elseif (method_exists($this, $methodName)) {
59
            return $this->$methodName(
60
                $sendResult
61
            );
62
        } else {
63
            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
    protected function analyzeSecurityAuthenticateResponse($response)
74
    {
75
        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
    protected function analyzeSecuritySignOutResponse($response)
85
    {
86
        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
    protected function analyzeCommandCrypticResponse($response)
96
    {
97
        $ccResult = new Result($response, Result::STATUS_UNKNOWN);
98
        $ccResult->messages[] = new Result\NotOk(
99
            0,
100
            "Response handling not supported for cryptic entries"
101
        );
102
103
        return $ccResult;
104
    }
105
106 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
        $analyzeResponse = new Result($response);
109
110
        $message = null;
111
112
        $domXpath = $this->makeDomXpath($response->responseXml);
113
114
        $codeNode = $domXpath->query("//m:errorOrWarningSection/m:errorOrWarningInfo//m:code")->item(0);
115
        if ($codeNode instanceof \DOMNode) {
116
            $analyzeResponse->status = Result::STATUS_ERROR;
117
118
            $categoryNode = $domXpath->query("//m:errorOrWarningSection/m:errorOrWarningInfo//m:type")->item(0);
119
            if ($categoryNode instanceof \DOMNode) {
120
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
121
            }
122
123
            $messageNodes = $domXpath->query('//m:errorOrWarningSection/m:textInformation/m:freeText');
124
            if ($messageNodes->length > 0) {
125
                $message = $this->makeMessageFromMessagesNodeList($messageNodes);
126
            }
127
            $analyzeResponse->messages [] = new Result\NotOk($codeNode->nodeValue, $message);
128
        }
129
130
        return $analyzeResponse;
131
    }
132
133
    protected function analyzeAirSellFromRecommendationResponse($response)
134
    {
135
        $analyzeResponse = new Result($response);
136
137
        $errMsgMap = [
138
            "288" => "UNABLE TO SATISFY, NEED CONFIRMED FLIGHT STATUS",
139
            "390" => "UNABLE TO REFORMAT"
140
        ];
141
142
        $domXpath = $this->makeDomXpath($response->responseXml);
143
144
        $codeNode = $domXpath->query("//m:errorSegment/m:errorDetails/m:errorCode")->item(0);
145
        if ($codeNode instanceof \DOMNode) {
146
            $analyzeResponse->status = Result::STATUS_ERROR;
147
148
            $categoryNode = $domXpath->query("//m:errorSegment/m:errorDetails/m:errorCategory")->item(0);
149
            if ($categoryNode instanceof \DOMNode) {
150
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
151
            }
152
153
            $message = (array_key_exists($codeNode->nodeValue, $errMsgMap)) ?
154
                $errMsgMap[$codeNode->nodeValue] : 'UNKNOWN ERROR';
155
156
            $analyzeResponse->messages [] = new Result\NotOk($codeNode->nodeValue, $message);
157
        }
158
159
        return $analyzeResponse;
160
    }
161
162
    /**
163
     * @param SendResult $response
164
     * @return Result
165
     */
166
    protected function analyzeAirFlightInfoResponse($response)
167
    {
168
        $analyzeResponse = new Result($response);
169
170
        $code = null;
171
        $message = null;
172
173
        $domXpath = $this->makeDomXpath($response->responseXml);
174
175
        $categoryNodes = $domXpath->query('//m:responseError/m:errorInfo/m:errorDetails/m:errorCategory');
176
        if ($categoryNodes->length > 0) {
177
            $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNodes->item(0)->nodeValue);
178
        }
179
180
        $codeNodes = $domXpath->query('//m:responseError/m:errorInfo/m:errorDetails/m:errorCode');
181
        if ($codeNodes->length > 0) {
182
            $code = $codeNodes->item(0)->nodeValue;
183
        }
184
185
        $messageNodes = $domXpath->query('//m:responseError/m:interactiveFreeText/m:freeText');
186
        if ($messageNodes->length > 0) {
187
            $message = $this->makeMessageFromMessagesNodeList($messageNodes);
188
        }
189
190
        if (!is_null($message) && !is_null($code)) {
191
            $analyzeResponse->messages[] = new Result\NotOk($code, $message);
192
        }
193
194
        return $analyzeResponse;
195
    }
196
197
    /**
198
     * @param SendResult $response
199
     * @return Result
200
     */
201
    protected function analyzeAirRetrieveSeatMapResponse($response)
202
    {
203
        $analyzeResponse = new Result($response);
204
205
        $code = null;
0 ignored issues
show
Unused Code introduced by
$code is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
206
        $message = null;
0 ignored issues
show
Unused Code introduced by
$message is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
207
208
        $domXpath = $this->makeDomXpath($response->responseXml);
209
210
        $errorCodeNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:code');
211 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...
212
            $analyzeResponse->status = Result::STATUS_ERROR;
213
214
            $errCode = $errorCodeNode->item(0)->nodeValue;
215
            $level = null;
216
            $errDesc = null;
0 ignored issues
show
Unused Code introduced by
$errDesc is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
217
218
            $errorLevelNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:processingLevel');
219
            if ($errorLevelNode->length > 0) {
220
                $level = RetrieveSeatMap::decodeProcessingLevel($errorLevelNode->item(0)->nodeValue);
221
            }
222
223
            $errorDescNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:description');
224
            if ($errorDescNode->length > 0) {
225
                $errDesc = $errorDescNode->item(0)->nodeValue;
226
            } else {
227
                $errDesc = RetrieveSeatMap::findMessage($errCode);
228
            }
229
230
            $analyzeResponse->messages[] = new Result\NotOk(
231
                $errCode,
232
                $errDesc,
233
                $level
234
            );
235
        }
236
237
        $codeNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:number');
238 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...
239
            $analyzeResponse->status = Result::STATUS_WARN;
240
241
            $warnCode = $codeNode->item(0)->nodeValue;
242
            $level = null;
243
            $warnDesc = null;
0 ignored issues
show
Unused Code introduced by
$warnDesc is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
244
245
            $levelNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:processingLevel');
246
            if ($levelNode->length > 0) {
247
                $level = RetrieveSeatMap::decodeProcessingLevel($levelNode->item(0)->nodeValue);
248
            }
249
250
            $descNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:description');
251
            if ($descNode->length > 0) {
252
                $warnDesc = $descNode->item(0)->nodeValue;
253
            } else {
254
                $warnDesc = RetrieveSeatMap::findMessage($warnCode);
255
            }
256
257
            $analyzeResponse->messages[] = new Result\NotOk(
258
                $warnCode,
259
                $warnDesc,
260
                $level
261
            );
262
        }
263
264
        return $analyzeResponse;
265
    }
266
267
    /**
268
     * Analysing a PNR_Retrieve response
269
     *
270
     * @param SendResult $response PNR_Retrieve result
271
     * @return Result
272
     */
273
    protected function analyzePnrRetrieveResponse($response)
274
    {
275
        return $this->analyzePnrReply($response);
276
    }
277
278
    /**
279
     * @param SendResult $response PNR_AddMultiElements result
280
     * @return Result
281
     */
282
    protected function analyzePnrAddMultiElementsResponse($response)
283
    {
284
        return $this->analyzePnrReply($response);
285
    }
286
287
    /**
288
     * @param SendResult $response PNR_Cancel result
289
     * @return Result
290
     */
291
    protected function analyzePnrCancelResponse($response)
292
    {
293
        return $this->analyzePnrReply($response);
294
    }
295
296
    /**
297
     * @param SendResult $response Pnr_RetrieveAndDisplay response
298
     * @return Result
299
     * @throws Exception
300
     */
301
    protected function analyzePnrRetrieveAndDisplayResponse($response)
302
    {
303
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
304
    }
305
306
    /**
307
     * Analysing a PNR_TransferOwnershipReply
308
     *
309
     * @param SendResult $response PNR_TransferOwnership response
310
     * @return Result
311
     * @throws Exception
312
     */
313
    protected function analyzePNRTransferOwnershipResponse($response)
314
    {
315
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
316
    }
317
318
    /**
319
     * Analysing a PNR_DisplayHistoryReply
320
     *
321
     * @param SendResult $response PNR_DisplayHistoryReply result
322
     * @return Result
323
     * @throws Exception
324
     */
325
    protected function analyzePnrDisplayHistoryResponse($response)
326
    {
327
        $analyzeResponse = new Result($response);
328
329
        $domXpath = $this->makeDomXpath($response->responseXml);
330
331
        $queryAllErrorCodes = "//m:generalErrorGroup//m:errorNumber/m:errorDetails/m:errorCode";
332
        $queryAllErrorMsg = "//m:generalErrorGroup/m:genrealErrorText/m:freeText";
333
334
        $errorCodeNodeList = $domXpath->query($queryAllErrorCodes);
335
336 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...
337
            $analyzeResponse->status = Result::STATUS_ERROR;
338
339
            $code = $errorCodeNodeList->item(0)->nodeValue;
340
            $errorTextNodeList = $domXpath->query($queryAllErrorMsg);
341
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
342
343
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message));
344
        }
345
346
        return $analyzeResponse;
347
    }
348
349
    /**
350
     * @param SendResult $response Queue_RemoveItem response
351
     * @return Result
352
     * @throws Exception
353
     */
354
    protected function analyzeQueueRemoveItemResponse($response)
355
    {
356
        return $this->analyzeGenericQueueResponse($response);
357
    }
358
359
    /**
360
     * @param SendResult $response Queue_MoveItem response
361
     * @return Result
362
     * @throws Exception
363
     */
364
    protected function analyzeQueueMoveItemResponse($response)
365
    {
366
        return $this->analyzeGenericQueueResponse($response);
367
    }
368
369
    /**
370
     * @param SendResult $response Queue_PlacePNR response
371
     * @return Result
372
     * @throws Exception
373
     */
374
    protected function analyzeQueuePlacePNRResponse($response)
375
    {
376
        return $this->analyzeGenericQueueResponse($response);
377
    }
378
379
    /**
380
     * @param SendResult $response Queue_List result
381
     * @return Result
382
     * @throws Exception
383
     */
384
    protected function analyzeQueueListResponse($response)
385
    {
386
        return $this->analyzeGenericQueueResponse($response);
387
    }
388
389
    /**
390
     * Analyze a generic Queue response
391
     *
392
     * @param SendResult $response Queue_*Reply result
393
     * @return Result
394
     * @throws Exception
395
     */
396
    protected function analyzeGenericQueueResponse($response)
397
    {
398
        $analysisResponse = new Result($response);
399
400
        $domDoc = $this->loadDomDocument($response->responseXml);
401
402
        $errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0);
403
404
        if (!is_null($errorCodeNode)) {
405
            $analysisResponse->status = Result::STATUS_WARN;
406
407
            $errorCode = $errorCodeNode->nodeValue;
408
            $errorMessage = $this->getErrorTextFromQueueErrorCode($errorCode);
409
410
            $analysisResponse->messages[] = new Result\NotOk($errorCode, $errorMessage);
411
        }
412
413
        return $analysisResponse;
414
    }
415
416
417
    /**
418
     * @param SendResult $response Fare_PricePNRWithBookingClass result
419
     * @return Result
420
     * @throws Exception
421
     */
422 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...
423
    {
424
        $analyzeResponse = new Result($response);
425
426
        $domXpath = $this->makeDomXpath($response->responseXml);
427
428
        $queryErrorCode = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
429
        $queryErrorCategory = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory";
430
        $queryErrorMsg = "//m:applicationError/m:errorWarningDescription/m:freeText";
431
432
        $errorCodeNodeList = $domXpath->query($queryErrorCode);
433
434
        if ($errorCodeNodeList->length > 0) {
435
            $analyzeResponse->status = Result::STATUS_ERROR;
436
437
            $errorCatNode = $domXpath->query($queryErrorCategory)->item(0);
438
            if ($errorCatNode instanceof \DOMNode) {
439
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
440
            }
441
442
            $analyzeResponse->messages[] = new Result\NotOk(
443
                $errorCodeNodeList->item(0)->nodeValue,
444
                $this->makeMessageFromMessagesNodeList(
445
                    $domXpath->query($queryErrorMsg)
446
                )
447
            );
448
        }
449
450
        return $analyzeResponse;
451
    }
452
453
    /**
454
     * @param SendResult $response Fare_PricePNRWithLowerFares result
455
     * @return Result
456
     * @throws Exception
457
     */
458
    protected function analyzeFarePricePNRWithLowerFaresResponse($response)
459
    {
460
        return $this->analyzeFarePricePNRWithBookingClassResponse($response);
461
    }
462
463
    /**
464
     * @param SendResult $response Fare_PricePNRWithLowestFare result
465
     * @return Result
466
     * @throws Exception
467
     */
468
    protected function analyzeFarePricePNRWithLowestFareResponse($response)
469
    {
470
        return $this->analyzeFarePricePNRWithBookingClassResponse($response);
471
    }
472
473
    /**
474
     * @param SendResult $response
475
     * @return Result
476
     */
477
    protected function analyzeFareMasterPricerCalendarResponse($response)
478
    {
479
        return $this->analyzeFareMasterPricerTravelBoardSearchResponse($response);
480
    }
481
482
    /**
483
     * @param SendResult $response
484
     * @return Result
485
     */
486
    protected function analyzeFareMasterPricerTravelBoardSearchResponse($response)
487
    {
488
        $analyzeResponse = new Result($response);
489
490
        $domXpath = $this->makeDomXpath($response->responseXml);
491
492
        $queryErrCode = "//m:applicationError//m:applicationErrorDetail/m:error";
493
        $queryErrMsg = "//m:errorMessageText/m:description";
494
495
        $codeNode = $domXpath->query($queryErrCode)->item(0);
496
497
        if ($codeNode instanceof \DOMNode) {
498
            $analyzeResponse->status = Result::STATUS_ERROR;
499
500
            $errMsg = '';
501
            $errMsgNode = $domXpath->query($queryErrMsg)->item(0);
502
            if ($errMsgNode instanceof \DOMNode) {
503
                $errMsg = $errMsgNode->nodeValue;
504
            }
505
506
            $analyzeResponse->messages[] = new Result\NotOk(
507
                $codeNode->nodeValue,
508
                $errMsg
509
            );
510
        }
511
512
        return $analyzeResponse;
513
    }
514
515
    /**
516
     * @param SendResult $response
517
     * @return Result
518
     */
519
    protected function analyzeFareConvertCurrencyResponse($response)
520
    {
521
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
522
    }
523
524
    /**
525
     * @param SendResult $response
526
     * @return Result
527
     */
528
    protected function analyzeFareCheckRulesResponse($response)
529
    {
530
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
531
    }
532
533
    /**
534
     * @param SendResult $response
535
     * @return Result
536
     */
537
    protected function analyzeFareInformativePricingWithoutPNRResponse($response)
538
    {
539
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
540
    }
541
542
    /**
543
     * @param SendResult $response
544
     * @return Result
545
     */
546
    protected function analyzeFareInformativeBestPricingWithoutPNRResponse($response)
547
    {
548
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
549
    }
550
551
    /**
552
     * @param SendResult $response
553
     * @return Result
554
     */
555
    protected function analyzeDocIssuanceIssueTicketResponse($response)
556
    {
557
        return $this->analyzeSimpleResponseErrorCodeAndMessageStatusCode($response);
558
    }
559
560
    /**
561
     * @param SendResult $response Ticket_DeleteTST result
562
     * @return Result
563
     */
564
    protected function analyzeTicketDisplayTSTResponse($response)
565
    {
566
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
567
    }
568
569
    /**
570
     * @param SendResult $response Ticket_DeleteTST result
571
     * @return Result
572
     */
573
    protected function analyzeTicketDeleteTSTResponse($response)
574
    {
575
        return $this->analyzeTicketCreateTSTFromPricingResponse($response);
576
    }
577
578
    /**
579
     * @param SendResult $response Ticket_CreateTSTFromPricing result
580
     * @return Result
581
     */
582 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...
583
    {
584
        $analyzeResponse = new Result($response);
585
586
        $domDoc = $this->loadDomDocument($response->responseXml);
587
588
        $errorCodeNode = $domDoc->getElementsByTagName("applicationErrorCode")->item(0);
589
590
        if (!is_null($errorCodeNode)) {
591
            $analyzeResponse->status = Result::STATUS_ERROR;
592
593
            $errorCatNode = $domDoc->getElementsByTagName("codeListQualifier")->item(0);
594
            if ($errorCatNode instanceof \DOMNode) {
595
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
596
            }
597
598
            $errorCode = $errorCodeNode->nodeValue;
599
            $errorTextNodeList = $domDoc->getElementsByTagName("errorFreeText");
600
601
            $analyzeResponse->messages[] = new Result\NotOk(
602
                $errorCode,
603
                $this->makeMessageFromMessagesNodeList($errorTextNodeList)
604
            );
605
        }
606
607
        return $analyzeResponse;
608
    }
609
610
    /**
611
     * @param SendResult $response
612
     * @return Result
613
     */
614
    protected function analyzeOfferConfirmCarOfferResponse($response)
615
    {
616
        return $this->analyzeGenericOfferResponse($response);
617
    }
618
619
    /**
620
     * @param SendResult $response
621
     * @return Result
622
     */
623
    protected function analyzeOfferConfirmHotelOfferResponse($response)
624
    {
625
        $analyzeResponse = new Result($response);
626
627
        $domXpath = $this->makeDomXpath($response->responseXml);
628
629
        $codeNode = $domXpath->query("//m:errorDetails/m:errorCode")->item(0);
630
        if ($codeNode instanceof \DOMNode) {
631
            $analyzeResponse->status = Result::STATUS_ERROR;
632
633
            $categoryNode = $domXpath->query("//m:errorDetails/m:errorCategory")->item(0);
634
            if ($categoryNode instanceof \DOMNode) {
635
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
636
            }
637
638
            $msgNode = $domXpath->query('//m:errorDescription/m:freeText')->item(0);
639
640
            $analyzeResponse->messages[] = new Result\NotOk(
641
                $codeNode->nodeValue,
642
                trim($msgNode->nodeValue)
643
            );
644
        }
645
646
        return $analyzeResponse;
647
    }
648
649
    /**
650
     * @param SendResult $response
651
     * @return Result
652
     */
653
    protected function analyzeOfferConfirmAirOfferResponse($response)
654
    {
655
        return $this->analyzeGenericOfferResponse($response);
656
    }
657
658
    /**
659
     * @param SendResult $response
660
     * @return Result
661
     */
662
    protected function analyzeOfferVerifyOfferResponse($response)
663
    {
664
        return $this->analyzeGenericOfferResponse($response);
665
    }
666
667
    protected function analyzeMiniRuleGetFromPricingRecResponse($response)
668
    {
669
        $analyzeResponse = new Result($response);
670
671
        $domXpath = $this->makeDomXpath($response->responseXml);
672
673
        $statusNode = $domXpath->query('//m:responseDetails/m:statusCode')->item(0);
674
        if ($statusNode instanceof \DOMNode) {
675
            $code = $statusNode->nodeValue;
676
677
            if ($code !== 'O') {
678
                $categoryNode = $domXpath->query('//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory')->item(0);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
679
                $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue);
680
681
                $codeNode = $domXpath->query('//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode')->item(0);
682
                $msgNode = $domXpath->query('//m:errorWarningDescription/m:freeText')->item(0);
683
684
                if ($codeNode instanceof \DOMNode && $msgNode instanceof \DOMNode) {
685
                    $analyzeResponse->messages[] = new Result\NotOk(
686
                        $codeNode->nodeValue,
687
                        $msgNode->nodeValue
688
                    );
689
                }
690
            }
691
        }
692
693
        return $analyzeResponse;
694
    }
695
696
    /**
697
     * @param SendResult $response
698
     * @return Result
699
     */
700
    protected function analyzeInfoEncodeDecodeCityResponse($response)
701
    {
702
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
703
    }
704
705
    /**
706
     * @param SendResult $response
707
     * @return Result
708
     */
709
    protected function analyzePriceXplorerExtremeSearchResponse($response)
710
    {
711
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
712
    }
713
714
    /**
715
     * @param SendResult $response
716
     * @return Result
717
     */
718
    protected function analyzeSalesReportsDisplayQueryReportResponse($response)
719
    {
720
        return $this->analyzeSimpleResponseErrorCodeAndMessage($response);
721
    }
722
}
723