RefundRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 8.51%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 0
loc 86
ccs 4
cts 47
cp 0.0851
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getSecret() 0 4 1
A setSecret() 0 4 1
A getPayeeAccount() 0 4 1
A setPayeeAccount() 0 4 1
A getData() 0 13 1
A sendData() 0 6 1
A soapCall() 0 40 2
1
<?php
2
/**
3
 * OKPAY driver for Omnipay PHP payment library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-okpay
6
 * @package   omnipay-okpay
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\OKPAY\Message;
12
13
use Omnipay\Common\Exception\InvalidRequestException;
14
15
class RefundRequest extends AbstractRequest
16
{
17
    protected $endpoint = 'https://api.okpay.com/OkPayAPI?wsdl';
18
19 1
    public function getSecret()
20
    {
21 1
        return $this->getParameter('secret');
22
    }
23
24 2
    public function setSecret($value)
25
    {
26 2
        return $this->setParameter('secret', $value);
27
    }
28
29
    public function getPayeeAccount()
30
    {
31
        return $this->getParameter('payeeAccount');
32
    }
33
34
    public function setPayeeAccount($value)
35
    {
36
        return $this->setParameter('payeeAccount', $value);
37
    }
38
39
    public function getData()
40
    {
41
        $this->validate('purse', 'payeeAccount', 'amount', 'secret', 'description');
42
43
        $data['secret'] = $this->getSecret();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
44
        $data['walletId'] = $this->getPurse();
45
        $data['receiver'] = $this->getPayeeAccount();
46
        $data['amount'] = $this->getAmount();
47
        $data['currency'] = $this->getCurrency();
48
        $data['description'] = $this->getDescription();
49
50
        return $data;
51
    }
52
53
    public function sendData($data)
54
    {
55
        $response = $this->soapCall($data);
56
57
        return $this->response = new RefundResponse($this, $response);
58
    }
59
60
    private function soapCall($data)
61
    {
62
        $datePart = gmdate('Ymd');
63
        $timePart = gmdate('H');
64
        $authString = "{$data['secret']}:{$datePart}:{$timePart}";
65
66
        $sha256 = bin2hex(hash('sha256', $authString, true));
67
        $secToken = strtoupper($sha256);
68
69
        try {
70
            $client = new \SoapClient(
71
                $this->endpoint, [
72
                    'soap_version' => SOAP_1_1,
73
                    'stream_context' => stream_context_create(
74
                        [
75
                            'ssl' => [
76
                                'verify_peer' => false,
77
                                'verify_peer_name' => false,
78
                            ],
79
                        ]
80
                    ),
81
                ]
82
            );
83
84
            $this->WalletID = $data['walletId'];
0 ignored issues
show
Bug introduced by
The property WalletID does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
85
            $this->SecurityToken = $secToken;
0 ignored issues
show
Bug introduced by
The property SecurityToken does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
86
            $this->Currency = $data['currency'];
0 ignored issues
show
Bug introduced by
The property Currency does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
87
            $this->Receiver = $data['receiver'];
0 ignored issues
show
Bug introduced by
The property Receiver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
88
            $this->Amount = $data['amount'];
0 ignored issues
show
Bug introduced by
The property Amount does not seem to exist. Did you mean negativeAmountAllowed?

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...
89
            $this->Comment = $data['description'];
0 ignored issues
show
Bug introduced by
The property Comment does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
90
            $this->IsReceiverPaysFees = false;
0 ignored issues
show
Bug introduced by
The property IsReceiverPaysFees does not seem to exist. Did you mean Receiver?

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...
91
92
            $webService = $client->Send_Money($this);
93
            $wsResult = $webService->Send_MoneyResult;
94
95
            return $wsResult;
96
        } catch (\Exception $e) {
97
            throw new InvalidRequestException($e->getMessage());
98
        }
99
    }
100
}
101