Passed
Push — master ( 533bb4...b887a7 )
by Dieter
06:33
created

HandlerValidateFOP::analyze()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 36
Code Lines 20

Duplication

Lines 21
Ratio 58.33 %

Code Coverage

Tests 22
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 21
loc 36
ccs 22
cts 22
cp 1
rs 8.8571
cc 3
eloc 20
nc 4
nop 1
crap 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\FOP;
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
 * HandlerValidateFOP
32
 *
33
 * @package Amadeus\Client\ResponseHandler\FOP
34
 * @author Mike Hernas <[email protected]>
35
 */
36
class HandlerValidateFOP extends StandardResponseHandler
37
{
38
    //General error
39
    const Q_G_ERR = "//m:transmissionError/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
40
    const Q_G_CAT = "//m:transmissionError/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory";
41
    const Q_G_MSG = "//m:transmissionError/m:errorWarningDescription/m:freeText";
42
    //Deficient FOP level:
43
    const Q_D_ERR = "//m:fopDescription/m:mopDescription/m:paymentModule/m:mopDetailedData//m:transactionStatus/m:errorOrWarningCodeDetails//m:errorCode";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 154 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
44
    const Q_D_CAT = "//m:fopDescription/m:mopDescription/m:paymentModule/m:mopDetailedData//m:transactionStatus/m:errorOrWarningCodeDetails//m:errorCategory";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 158 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
45
    const Q_D_MSG = "//m:fopDescription/m:mopDescription/m:paymentModule/m:mopDetailedData//m:transactionStatus/m:errorWarningDescription//m:freeText";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 151 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
46
   
47
    /**
48
     * FOP_ValidateFormOfPayment Analyze the result from the message operation and check for any error messages
49
     *
50
     * @param SendResult $response
51
     * @return Result
52
     * @throws Exception
53
     */
54 1
    public function analyze(SendResult $response)
55
    {
56 1
        $analyzeResponse = new Result($response);
57
58 1
        $domXpath = $this->makeDomXpath($response->responseXml);
59
60
        //General error level in the transmissionError location:
61 1
        $errorCodeNodeList = $domXpath->query(self::Q_G_ERR);
62 1 View Code Duplication
        if ($errorCodeNodeList->length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
63 1
            $errorCatNode = $domXpath->query(self::Q_G_CAT)->item(0);
64 1
            $analyzeResponse->setStatus($this->makeStatusForPotentiallyNonExistent($errorCatNode));
65
66 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
67 1
            $errorTextNodeList = $domXpath->query(self::Q_G_MSG);
68 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
69
70 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general');
71 1
        }
72
73
        //Deficient FOP level errors:
74 1
        $errorCodeNodeList = $domXpath->query(self::Q_D_ERR);
75
76 1 View Code Duplication
        if ($errorCodeNodeList->length > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
77 1
            $errorCatNode = $domXpath->query(self::Q_D_CAT)->item(0);
78 1
            $analyzeResponse->setStatus($this->makeStatusForPotentiallyNonExistent($errorCatNode));
79
80 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
81
82 1
            $errorTextNodeList = $domXpath->query(self::Q_D_MSG);
83 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
84
85 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'deficient_fop');
86 1
        }
87
88 1
        return $analyzeResponse;
89
    }
90
91
    /**
92
     * Make status from a category DOMNode or default status.
93
     *
94
     * @param \DOMNode|null $errorCatNode
95
     * @return string
96
     */
97 1 View Code Duplication
    protected function makeStatusForPotentiallyNonExistent($errorCatNode)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
98
    {
99 1
        if ($errorCatNode instanceof \DOMNode) {
100 1
            $status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
101 1
        } else {
102 1
            $status = Result::STATUS_ERROR;
103
        }
104
105 1
        return $status;
106
    }
107
}
108