Passed
Branch fopcreatefop (fcebe7)
by Dieter
08:14
created

HandlerCreateFormOfPayment::analyze()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 67
Code Lines 36

Duplication

Lines 42
Ratio 62.69 %

Code Coverage

Tests 40
CRAP Score 5

Importance

Changes 0
Metric Value
dl 42
loc 67
ccs 40
cts 40
cp 1
rs 8.5896
c 0
b 0
f 0
cc 5
eloc 36
nc 16
nop 1
crap 5

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * HandlerCreateFormOfPayment
32
 *
33
 * @package Amadeus\Client\ResponseHandler\FOP
34
 * @author Dieter Devlieghere <[email protected]>
35
 */
36
class HandlerCreateFormOfPayment 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
    //FP level error
43
    const Q_F_ERR = "//m:fopDescription//m:fpElementError/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
44
    const Q_F_CAT = "//m:fopDescription//m:fpElementError/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory";
45
    const Q_F_MSG = "//m:fopDescription//m:fpElementError/m:errorWarningDescription/m:freeText";
46
    //Deficient FOP level:
47
    const Q_D_ERR = "//m:fopDescription/m:mopDescription/m:mopElementError/m:errorOrWarningCodeDetails//m:errorCode";
48
    const Q_D_CAT = "//m:fopDescription/m:mopDescription/m:mopElementError/m:errorOrWarningCodeDetails//m:errorCategory";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
49
    const Q_D_MSG = "//m:fopDescription/m:mopDescription/m:mopElementError/m:errorWarningDescription/m:freeText";
50
    //Authorization failure:
51
    const Q_A_ERR = "//m:fopDescription/m:mopDescription/m:paymentModule//m:paymentStatusError/m:errorOrWarningCodeDetails//m:errorCode";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 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...
52
    const Q_A_CAT = "//m:fopDescription/m:mopDescription/m:paymentModule//m:paymentStatusError/m:errorOrWarningCodeDetails//m:errorCategory";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 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...
53
    const Q_A_MSG = "//m:fopDescription/m:mopDescription/m:paymentModule//m:paymentStatusError/m:errorWarningDescription/m:freeText";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 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...
54
55
    /**
56
     * FOP_CreateFormOfPayment Analyze the result from the message operation and check for any error messages
57
     *
58
     * @param SendResult $response
59
     * @return Result
60
     * @throws Exception
61
     */
62 4
    public function analyze(SendResult $response)
63
    {
64
        //TODO
65 4
        $analyzeResponse = new Result($response);
66
67 4
        $domXpath = $this->makeDomXpath($response->responseXml);
68
69
        //General error level in the transmissionError location:
70 4
        $errorCodeNodeList = $domXpath->query(self::Q_G_ERR);
71
72 4 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...
73 1
            $errorCatNode = $domXpath->query(self::Q_G_CAT)->item(0);
74 1
            $analyzeResponse->setStatus($this->makeStatusForPotentiallyNonExistent($errorCatNode));
75
76 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
77 1
            $errorTextNodeList = $domXpath->query(self::Q_G_MSG);
78 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
79
80 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general');
81 1
        }
82
83
        //FP level errors via the fopDescription/fpElementError data:
84 4
        $errorCodeNodeList = $domXpath->query(self::Q_F_ERR);
85
86 4 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...
87 1
            $errorCatNode = $domXpath->query(self::Q_F_CAT)->item(0);
88 1
            $analyzeResponse->setStatus($this->makeStatusForPotentiallyNonExistent($errorCatNode));
89
90 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
91 1
            $errorTextNodeList = $domXpath->query(self::Q_F_MSG);
92 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
93
94 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'fp');
95 1
        }
96
97
        //Deficient FOP level errors:
98 4
        $errorCodeNodeList = $domXpath->query(self::Q_D_ERR);
99
100 4 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...
101 1
            $errorCatNode = $domXpath->query(self::Q_D_CAT)->item(0);
102 1
            $analyzeResponse->setStatus($this->makeStatusForPotentiallyNonExistent($errorCatNode));
103
104 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
105
106 1
            $errorTextNodeList = $domXpath->query(self::Q_D_MSG);
107 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
108
109 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'deficient_fop');
110 1
        }
111
112
        //authorization failure:
113 4
        $errorCodeNodeList = $domXpath->query(self::Q_A_ERR);
114
115 4 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...
116 1
            $errorCatNode = $domXpath->query(self::Q_A_CAT)->item(0);
117 1
            $analyzeResponse->setStatus($this->makeStatusForPotentiallyNonExistent($errorCatNode));
118
119 1
            $code = $errorCodeNodeList->item(0)->nodeValue;
120
121 1
            $errorTextNodeList = $domXpath->query(self::Q_A_MSG);
122 1
            $message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);
123
124 1
            $analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'authorization_failure');
125 1
        }
126
127 4
        return $analyzeResponse;
128
    }
129
130
    /**
131
     * Make status from a category DOMNode or default status.
132
     *
133
     * @param \DOMNode|null $errorCatNode
134
     * @return string
135
     */
136 2
    protected function makeStatusForPotentiallyNonExistent($errorCatNode)
137
    {
138 2
        if ($errorCatNode instanceof \DOMNode) {
139 1
            $status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
140 1
        } else {
141 1
            $status = Result::STATUS_ERROR;
142
        }
143
144 2
        return $status;
145
    }
146
}
147