|
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\PNR; |
|
24
|
|
|
|
|
25
|
|
|
use Amadeus\Client\ResponseHandler\StandardResponseHandler; |
|
26
|
|
|
use Amadeus\Client\Result; |
|
27
|
|
|
use Amadeus\Client\Session\Handler\SendResult; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* HandlerRetrieve |
|
31
|
|
|
* |
|
32
|
|
|
* @package Amadeus\Client\ResponseHandler\PNR |
|
33
|
|
|
* @author Dieter Devlieghere <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class HandlerRetrieve extends StandardResponseHandler |
|
36
|
|
|
{ |
|
37
|
|
|
const Q_G_ERR = "//m:generalErrorInfo//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
|
38
|
|
|
const Q_G_MSG = "//m:generalErrorInfo/m:errorWarningDescription/m:freeText"; |
|
39
|
|
|
const Q_G_OLD_ERR = "//m:generalErrorInfo//m:messageErrorInformation/m:errorDetail/m:errorCode"; |
|
40
|
|
|
const Q_G_OLD_MSG = "//m:generalErrorInfo/m:messageErrorText/m:text"; |
|
41
|
|
|
const Q_S_ERR = "//m:originDestinationDetails//m:errorInfo/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
|
42
|
|
|
const Q_S_MSG = "//m:originDestinationDetails//m:errorInfo/m:errorWarningDescription/m:freeText"; |
|
43
|
|
|
const Q_E_ERR = "//m:dataElementsIndiv/m:elementErrorInformation/m:errorOrWarningCodeDetails//m:errorCode"; |
|
44
|
|
|
const Q_E_MSG = "//m:dataElementsIndiv//m:elementErrorInformation/m:errorWarningDescription/m:freeText"; |
|
45
|
|
|
const Q_P_ERR = "//m:travellerInfo/m:nameError/m:errorOrWarningCodeDetails//m:errorCode"; |
|
46
|
|
|
const Q_P_MSG = "//m:travellerInfo/m:nameError/m:errorWarningDescription/m:freeText"; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Analysing a PNR_Reply |
|
50
|
|
|
* |
|
51
|
|
|
* @param SendResult $response |
|
52
|
|
|
* @return Result |
|
53
|
|
|
*/ |
|
54
|
|
|
public function analyze(SendResult $response) |
|
55
|
|
|
{ |
|
56
|
|
|
$analyzeResponse = new Result($response); |
|
57
|
|
|
|
|
58
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
|
59
|
|
|
|
|
60
|
|
|
//General Errors: |
|
61
|
|
|
$errorCodeNodeList = $domXpath->query(self::Q_G_ERR); |
|
62
|
|
|
|
|
63
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
|
|
64
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
|
65
|
|
|
|
|
66
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
|
67
|
|
|
$errorTextNodeList = $domXpath->query(self::Q_G_MSG); |
|
68
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
|
69
|
|
|
|
|
70
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
//General Errors - PNR_Reply v 14.1 and below: |
|
74
|
|
|
$errorCodeNodeList = $domXpath->query(self::Q_G_OLD_ERR); |
|
75
|
|
|
|
|
76
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
|
|
77
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
|
78
|
|
|
|
|
79
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
|
80
|
|
|
$errorTextNodeList = $domXpath->query(self::Q_G_OLD_MSG); |
|
81
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
|
82
|
|
|
|
|
83
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
//Passenger error |
|
87
|
|
|
$errorCodeNodeList = $domXpath->query(self::Q_P_ERR); |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
|
|
90
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
|
91
|
|
|
|
|
92
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
|
93
|
|
|
$errorTextNodeList = $domXpath->query(self::Q_P_MSG); |
|
94
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
|
95
|
|
|
|
|
96
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'passenger'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
//Segment errors: |
|
100
|
|
|
$errorCodeNodeList = $domXpath->query(self::Q_S_ERR); |
|
101
|
|
|
|
|
102
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
|
|
103
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
|
104
|
|
|
|
|
105
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
|
106
|
|
|
$errorTextNodeList = $domXpath->query(self::Q_S_MSG); |
|
107
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
|
108
|
|
|
|
|
109
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'segment'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
//Element errors: |
|
113
|
|
|
$errorCodeNodeList = $domXpath->query(self::Q_E_ERR); |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
|
|
116
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
|
117
|
|
|
|
|
118
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
|
119
|
|
|
|
|
120
|
|
|
$errorTextNodeList = $domXpath->query(self::Q_E_MSG); |
|
121
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
|
122
|
|
|
|
|
123
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'element'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $analyzeResponse; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
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.