Passed
Pull Request — master (#489)
by Artem
05:00
created

HandlerDeleteVirtualCard::analyze()   A

Complexity

Conditions 6
Paths 16

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 29
rs 9.1111
cc 6
nc 16
nop 1
1
<?php
2
3
/**
4
 * amadeus-ws-client
5
 *
6
 * Copyright 2015 Amadeus Benelux NV
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 *
20
 * @package Amadeus
21
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
22
 */
23
24
namespace Amadeus\Client\ResponseHandler\PAY;
25
26
use Amadeus\Client\Exception;
27
use Amadeus\Client\ResponseHandler\StandardResponseHandler;
28
use Amadeus\Client\Result;
29
use Amadeus\Client\Session\Handler\SendResult;
30
31
/**
32
 * HandlerDeleteVirtualCard
33
 *
34
 * @package Amadeus\Client\ResponseHandler\PAY
35
 * @author Konstantin Bogomolov <[email protected]>
36
 */
37
class HandlerDeleteVirtualCard extends StandardResponseHandler
38
{
39
    /**
40
     * Analyze the result from the message operation and check for any error messages
41
     *
42
     * @param SendResult $response
43
     * @return Result
44
     * @throws Exception
45
     */
46
    public function analyze(SendResult $response)
47
    {
48
        $analyzeResponse = new Result($response);
49
50
        $code = null;
51
        $message = null;
52
53
        $domXpath = $this->makeDomXpath($response->responseXml);
54
55
        $categoryNodes = $domXpath->query('//ama:Errors/ama:Error/@Type');
56
        if ($categoryNodes->length > 0) {
57
            $analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNodes->item(0)->nodeValue);
58
        }
59
60
        $codeNodes = $domXpath->query('//ama:Errors/ama:Error/@Code');
61
        if ($codeNodes->length > 0) {
62
            $code = $codeNodes->item(0)->nodeValue;
63
        }
64
65
        $messageNodes = $domXpath->query('//ama:Errors/ama:Error/@ShortText');
66
        if ($messageNodes->length > 0) {
67
            $message = $this->makeMessageFromMessagesNodeList($messageNodes);
68
        }
69
70
        if (!is_null($message) && !is_null($code)) {
71
            $analyzeResponse->messages[] = new Result\NotOk($code, $message);
72
        }
73
74
        return $analyzeResponse;
75
    }
76
}
77