Completed
Push — master ( 48ab8a...13f83a )
by Dieter
05:33
created

HandlerList::analyze()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
crap 2
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\ResponseHandler\StandardResponseHandler;
26
use Amadeus\Client\Result;
27
use Amadeus\Client\Session\Handler\SendResult;
28
29
/**
30
 * HandlerList
31
 *
32
 * @package Amadeus\Client\ResponseHandler\Queue
33
 * @author Dieter Devlieghere <[email protected]>
34
 */
35
class HandlerList extends StandardResponseHandler
36
{
37 6
    public function analyze(SendResult $response)
38
    {
39 6
        $analysisResponse = new Result($response);
40
41 6
        $domDoc = $this->loadDomDocument($response->responseXml);
42
43 6
        $errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0);
44
45 6
        if (!is_null($errorCodeNode)) {
46 3
            $analysisResponse->status = Result::STATUS_WARN;
47
48 3
            $errorCode = $errorCodeNode->nodeValue;
49 3
            $errorMessage = $this->getErrorTextFromQueueErrorCode($errorCode);
50
51 3
            $analysisResponse->messages[] = new Result\NotOk($errorCode, $errorMessage);
52 3
        }
53
54 6
        return $analysisResponse;
55
    }
56
57
    /**
58
     * Returns the errortext from a Queue_*Reply errorcode
59
     *
60
     * This function is necessary because the core only responds
61
     * with errorcode but does not send an errortext.
62
     *
63
     * The errorcodes for all Queue_*Reply messages are the same.
64
     *
65
     * @link https://webservices.amadeus.com/extranet/viewArea.do?id=10
66
     * @param string $errorCode
67
     * @return string the errortext for this errorcode.
68
     */
69 3
    protected function getErrorTextFromQueueErrorCode($errorCode)
70
    {
71
        $recognizedErrors = [
72 3
            '1' => 'Invalid date',
73 3
            '360' => 'Invalid PNR file address',
74 3
            '723' => 'Invalid category',
75 3
            '727' => 'Invalid amount',
76 3
            '79A' => 'Invalid office identification',
77 3
            '79B' => 'Already working another queue',
78 3
            '79C' => 'Not allowed to access queues for specified office identification',
79 3
            '79D' => 'Queue identifier has not been assigned for specified office identification',
80 3
            '79E' => 'Attempting to perform a queue function when not associated with a queue',
81 3
            '79F' => 'Queue placement or add new queue item is not allowed for the specified office and queue',
82 3
            '911' => 'Unable to process - system error',
83 3
            '912' => 'Incomplete message - data missing in query',
84 3
            '913' => 'Item/data not found or data not existing in processing host',
85 3
            '914' => 'Invalid format/data - data does not match EDIFACT rules',
86 3
            '915' => 'No action - processing host cannot support function',
87 3
            '916' => 'EDIFACT version not supported',
88 3
            '917' => 'EDIFACT message size exceeded',
89 3
            '918' => 'Enter message in remarks',
90 3
            '919' => 'No PNR in AAA',
91 3
            '91A' => 'Inactive queue bank',
92 3
            '91B' => 'Nickname not found',
93 3
            '91C' => 'Invalid record locator',
94 3
            '91D' => 'Invalid format',
95 3
            '91F' => 'Invalid queue number',
96 3
            '920' => 'Queue/date range empty',
97 3
            '921' => 'Target not specified',
98 3
            '922' => 'Targetted queue has wrong queue type',
99 3
            '923' => 'Invalid time',
100 3
            '924' => 'Invalid date range',
101 3
            '925' => 'Queue number not specified',
102 3
            '926' => 'Queue category empty',
103 3
            '927' => 'No items exist',
104 3
            '928' => 'Queue category not assigned',
105 3
            '929' => 'No more items',
106
            '92A' => '>ueue category full'
107 3
        ];
108
109 3
        $errorMessage = (array_key_exists($errorCode, $recognizedErrors)) ? $recognizedErrors[$errorCode] : '';
110
111 3
        if ($errorMessage === '') {
112 1
            $errorMessage = "QUEUE ERROR '".$errorCode."' (Error message unavailable)";
113 1
        }
114
115 3
        return $errorMessage;
116
    }
117
}
118