DecryptResponse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 17.19 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 4
c 4
b 0
f 3
lcom 1
cbo 1
dl 11
loc 64
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getCustomInfoToArray() 11 11 2

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
 * This file is part of the GestPayWS library.
5
 *
6
 * (c) Manuel Dalla Lana <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EndelWar\GestPayWS\Response;
13
14
/**
15
 * Class DecryptResponse
16
 * @package EndelWar\GestPayWS
17
 */
18
class DecryptResponse extends Response
19
{
20
    protected $parametersName = array(
21
        // Mandatory
22
        'TransactionType',
23
        'TransactionResult',
24
        'ShopTransactionID',
25
        'BankTransactionID',
26
        'AuthorizationCode',
27
        'Currency',
28
        'Amount',
29
        'ErrorCode',
30
        'ErrorDescription',
31
32
        // Optional
33
        'Country',
34
        'CustomInfo',
35
        'Buyer', // contains BuyerName and BuyerEmail
36
        'TDLevel',
37
        'AlertCode',
38
        'AlertDescription',
39
        'CVVPresent',
40
        'MaskedPAN',
41
        'PaymentMethod',
42
        'TOKEN',
43
        'ProductType',
44
        'TokenExpiryMonth',
45
        'TokenExpiryYear',
46
        'TransactionKey',
47
        'VbV',
48
        'VbVRisp',
49
        'VbVBuyer',
50
        'VbVFlag',
51
    );
52
    protected $separator = '*P1*';
53
54
    /**
55
     * @param \stdClass $soapResponse
56
     * @throws \Exception
57
     */
58 15
    public function __construct($soapResponse)
59
    {
60 15
        $xml = simplexml_load_string($soapResponse->DecryptResult->any);
61 15
        if (isset($xml->CustomInfo)) {
62 15
            $xml->CustomInfo = urldecode($xml->CustomInfo);
0 ignored issues
show
Bug introduced by
The property CustomInfo does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
63 15
        }
64 15
        parent::__construct($xml);
65 15
    }
66
67
    /**
68
     * @return array
69
     */
70 1 View Code Duplication
    public function getCustomInfoToArray()
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...
71
    {
72 1
        $allinfo = explode($this->separator, $this->data['CustomInfo']);
73 1
        $customInfoArray = array();
74 1
        foreach ($allinfo as $singleInfo) {
75 1
            $tagvalue = explode('=', $singleInfo);
76 1
            $customInfoArray[$tagvalue[0]] = urldecode($tagvalue[1]);
77 1
        }
78
79 1
        return $customInfoArray;
80
    }
81
}
82