DecryptResponse::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
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