Test Failed
Pull Request — master (#368)
by
unknown
14:35
created

AbstractCardDetailsResponseHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 26.23 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 16
loc 61
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B fillCardDetails() 16 58 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ResponseHandler\StandardResponseHandler;
27
28
/**
29
 * VirtualCardDetailsBaseResponseHandler
30
 *
31
 * @package Amadeus\Client\ResponseHandler\PAY
32
 * @author Konstantin Bogomolov <[email protected]>
33
 */
34
abstract class AbstractCardDetailsResponseHandler extends StandardResponseHandler
35
{
36
    protected function fillCardDetails($analyzeResponse, $domXpath)
37
    {
38
        $cardNumber = $domXpath->query('//fop:PrimaryAccountNumber');
39
        if ($cardNumber->length > 0) {
40
            $analyzeResponse->response->Success->VirtualCard->Card->PrimaryAccountNumber =
41
                $cardNumber->item(0)->nodeValue;
42
        }
43
44
        $cvvNumber = $domXpath->query('//fop:CVV');
45
        if ($cardNumber->length > 0) {
46
            $analyzeResponse->response->Success->VirtualCard->Card->CVV =
47
                $cvvNumber->item(0)->nodeValue;
48
        }
49
50
        $address = $domXpath->query('//fop:AddressVerificationSystemValue');
51
        if ($address->length > 0) {
52
            $analyzeResponse->response->Success->VirtualCard->Card->AddressVerificationSystemValue->Line =
53
                $address->item(0)->nodeValue;
54
            $analyzeResponse->response->Success->VirtualCard->Card->AddressVerificationSystemValue->CityName =
55
                $address->item(0)->getAttribute('CityName');
56
            $analyzeResponse->response->Success->VirtualCard->Card->AddressVerificationSystemValue->PostalCode =
57
                $address->item(0)->getAttribute('PostalCode');
58
            $analyzeResponse->response->Success->VirtualCard->Card->AddressVerificationSystemValue->Country =
59
                $address->item(0)->getAttribute('Country');
60
        }
61
62
        $limitations = $domXpath->query('//pay:Limitations');
63
        if ($limitations->length > 0) {
64
            $limitationsNodes = $limitations->item(0)->childNodes;
65
            $analyzeResponse->response->Success->VirtualCard->AllowedTransactions =
66
                $limitationsNodes->item(0)->getAttribute('Maximum');
67
            $analyzeResponse->response->Success->VirtualCard->ValidityPeriod =
68
                $limitationsNodes->item(1)->getAttribute('EndDate');
69
        }
70
71
72
        $balance = $domXpath->query('//pay:Value[@Type=\'AvailableBalance\']');
73 View Code Duplication
        if ($balance->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...
74
            $analyzeResponse->response->Success->VirtualCard->Amount =
75
                $balance->item(0)->getAttribute('Amount');
76
            $analyzeResponse->response->Success->VirtualCard->DecimalPlaces =
77
                $balance->item(0)->getAttribute('DecimalPlaces');
78
            $analyzeResponse->response->Success->VirtualCard->CurrencyCode =
79
                $balance->item(0)->getAttribute('CurrencyCode');
80
        }
81
82
        $balance = $domXpath->query('//pay:Value[@Type=\'OnCard\']');
83 View Code Duplication
        if ($balance->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...
84
            $analyzeResponse->response->Success->VirtualCard->Amount =
85
                $balance->item(0)->getAttribute('Amount');
86
            $analyzeResponse->response->Success->VirtualCard->DecimalPlaces =
87
                $balance->item(0)->getAttribute('DecimalPlaces');
88
            $analyzeResponse->response->Success->VirtualCard->CurrencyCode =
89
                $balance->item(0)->getAttribute('CurrencyCode');
90
        }
91
92
        return $analyzeResponse;
93
    }
94
}
95