Passed
Push — master ( 347387...5b95ab )
by Artem
03:35
created

HandlerList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 50
c 1
b 0
f 0
dl 0
loc 81
ccs 52
cts 52
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A analyze() 0 18 2
A getErrorTextFromQueueErrorCode() 0 47 3
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 30
    public function analyze(SendResult $response)
38
    {
39 30
        $analysisResponse = new Result($response);
40
41 30
        $domDoc = $this->loadDomDocument($response->responseXml);
42
43 30
        $errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0);
44
45 30
        if (!is_null($errorCodeNode)) {
46 15
            $analysisResponse->status = Result::STATUS_WARN;
47
48 15
            $errorCode = $errorCodeNode->nodeValue;
49 15
            $errorMessage = $this->getErrorTextFromQueueErrorCode($errorCode);
50
51 15
            $analysisResponse->messages[] = new Result\NotOk($errorCode, $errorMessage);
52 6
        }
53
54 30
        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 15
    protected function getErrorTextFromQueueErrorCode($errorCode)
70
    {
71
        $recognizedErrors = [
72 15
            '1' => 'Invalid date',
73 6
            '360' => 'Invalid PNR file address',
74 6
            '723' => 'Invalid category',
75 6
            '727' => 'Invalid amount',
76 6
            '79A' => 'Invalid office identification',
77 6
            '79B' => 'Already working another queue',
78 6
            '79C' => 'Not allowed to access queues for specified office identification',
79 6
            '79D' => 'Queue identifier has not been assigned for specified office identification',
80 6
            '79E' => 'Attempting to perform a queue function when not associated with a queue',
81 6
            '79F' => 'Queue placement or add new queue item is not allowed for the specified office and queue',
82 6
            '911' => 'Unable to process - system error',
83 6
            '912' => 'Incomplete message - data missing in query',
84 6
            '913' => 'Item/data not found or data not existing in processing host',
85 6
            '914' => 'Invalid format/data - data does not match EDIFACT rules',
86 6
            '915' => 'No action - processing host cannot support function',
87 6
            '916' => 'EDIFACT version not supported',
88 6
            '917' => 'EDIFACT message size exceeded',
89 6
            '918' => 'Enter message in remarks',
90 6
            '919' => 'No PNR in AAA',
91 6
            '91A' => 'Inactive queue bank',
92 6
            '91B' => 'Nickname not found',
93 6
            '91C' => 'Invalid record locator',
94 6
            '91D' => 'Invalid format',
95 6
            '91F' => 'Invalid queue number',
96 6
            '920' => 'Queue/date range empty',
97 6
            '921' => 'Target not specified',
98 6
            '922' => 'Targetted queue has wrong queue type',
99 6
            '923' => 'Invalid time',
100 6
            '924' => 'Invalid date range',
101 6
            '925' => 'Queue number not specified',
102 6
            '926' => 'Queue category empty',
103 6
            '927' => 'No items exist',
104 6
            '928' => 'Queue category not assigned',
105 6
            '929' => 'No more items',
106
            '92A' => '>ueue category full'
107 6
        ];
108
109 15
        $errorMessage = (array_key_exists($errorCode, $recognizedErrors)) ? $recognizedErrors[$errorCode] : '';
110
111 15
        if ($errorMessage === '') {
112 5
            $errorMessage = "QUEUE ERROR '".$errorCode."' (Error message unavailable)";
113 2
        }
114
115 15
        return $errorMessage;
116
    }
117
}
118