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

VerifiedData::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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