Completed
Push — master ( ac749f...8181ea )
by Vuong
01:54
created

VerifiedData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 17.78 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 8
loc 45
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 8 8 1
B validateSecureHash() 0 19 5

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
 * @link https://github.com/yiiviet/yii2-payment
4
 * @copyright Copyright (c) 2017 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\payment\onepay;
9
10
use yii\helpers\ArrayHelper;
11
use yiiviet\payment\VerifiedData as BaseVerifiedData;
12
13
/**
14
 * Class VerifiedData
15
 *
16
 * @method PaymentClient getClient()
17
 *
18
 * @property PaymentClient $client
19
 *
20
 * @author Vuong Minh <[email protected]>
21
 * @since 1.0
22
 */
23
class VerifiedData extends BaseVerifiedData
24
{
25
26
    use MagicPropertiesTrait;
27
28
    /**
29
     * @inheritdoc
30
     */
31 4 View Code Duplication
    public function rules()
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...
32
    {
33
        return [
34 4
            [['vpc_SecureHash'], 'validateSecureHash', 'message' => '{attribute} is not valid!', 'on' => [
35
                PaymentGateway::VRC_IPN, PaymentGateway::VRC_PURCHASE_SUCCESS
36
            ], 'skipOnEmpty' => false]
37
        ];
38
    }
39
40
    /**
41
     * Phương thức kiểm tra chữ ký dữ liệu nhận từ OnePay.
42
     *
43
     * @param string $attribute Attribute chứa giá trị chữ ký cần kiểm tra.
44
     * @param array $params Mảng các tham trị được thiết lập từ rule.
45
     * @param \yii\validators\InlineValidator $validator Đối tượng thực thi kiểm tra.
46
     * @throws \yii\base\InvalidConfigException|\yii\base\NotSupportedException
47
     */
48 4
    public function validateSecureHash($attribute, $params, \yii\validators\InlineValidator $validator)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50 4
        $data = $this->get(false);
51 4
        $expectSignature = ArrayHelper::remove($data, $attribute, false);
52 4
        $dataSign = [];
53
54 4
        foreach ($data as $param => $value) {
55
            if (strpos($param, 'vpc_') === 0) {
56
                $dataSign[$param] = $value;
57
            }
58
        }
59
60 4
        ksort($dataSign);
61 4
        $data = urldecode(http_build_query($dataSign));
62
63 4
        if (!$expectSignature || !$this->getClient()->validateSignature($data, $expectSignature)) {
64 4
            $validator->addError($this, $attribute, $validator->message);
65
        }
66 4
    }
67
}
68