Completed
Push — master ( 27f914...b1731d )
by Dieter
05:26
created

HandlerList::getErrorTextFromQueueErrorCode()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 17
nc 4
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\Queue;
24
25
use Amadeus\Client\Exception;
26
use Amadeus\Client\ResponseHandler\StandardResponseHandler;
27
use Amadeus\Client\Result;
28
use Amadeus\Client\Session\Handler\SendResult;
29
30
/**
31
 * HandlerList
32
 *
33
 * @package Amadeus\Client\ResponseHandler\Queue
34
 * @author Dieter Devlieghere <[email protected]>
35
 */
36
class HandlerList extends StandardResponseHandler
37
{
38
    public function analyze(SendResult $response)
39
    {
40
        $analysisResponse = new Result($response);
41
42
        $domDoc = $this->loadDomDocument($response->responseXml);
43
44
        $errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0);
45
46
        if (!is_null($errorCodeNode)) {
47
            $analysisResponse->status = Result::STATUS_WARN;
48
49
            $errorCode = $errorCodeNode->nodeValue;
50
            $errorMessage = $this->getErrorTextFromQueueErrorCode($errorCode);
51
52
            $analysisResponse->messages[] = new Result\NotOk($errorCode, $errorMessage);
53
        }
54
55
        return $analysisResponse;
56
    }
57
58
    /**
59
     * Returns the errortext from a Queue_*Reply errorcode
60
     *
61
     * This function is necessary because the core only responds
62
     * with errorcode but does not send an errortext.
63
     *
64
     * The errorcodes for all Queue_*Reply messages are the same.
65
     *
66
     * @link https://webservices.amadeus.com/extranet/viewArea.do?id=10
67
     * @param string $errorCode
68
     * @return string the errortext for this errorcode.
69
     */
70
    protected function getErrorTextFromQueueErrorCode($errorCode)
71
    {
72
        $recognizedErrors = [
73
            '723' => "Invalid category",
74
            '911' => "Unable to process - system error",
75
            '913' => "Item/data not found or data not existing in processing host",
76
            '79D' => "Queue identifier has not been assigned for specified office identification",
77
            '91C' => "invalid record locator",
78
            '91F' => "Invalid queue number",
79
            '921' => "target not specified",
80
            '922' => "Targetted queue has wrong queue type",
81
            '926' => "Queue category empty",
82
            '928' => "Queue category not assigned",
83
            '92A' => "Queue category full",
84
        ];
85
86
        $errorMessage = (array_key_exists($errorCode, $recognizedErrors)) ? $recognizedErrors[$errorCode] : '';
87
88
        if ($errorMessage === '') {
89
            $errorMessage = "QUEUE ERROR '".$errorCode."' (Error message unavailable)";
90
        }
91
92
        return $errorMessage;
93
    }
94
}
95