DataSignature   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 40
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 10 3
A validate() 0 6 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\vnpayment;
9
10
use yii\base\InvalidConfigException;
11
use yiiviet\payment\DataSignature as BaseDataSignature;
12
13
/**
14
 * Lớp DataSignature hổ trợ tạo và kiểm tra chữ ký dữ liệu khi tương tác với VnPayment.
15
 *
16
 * @property string $secureHash
17
 *
18
 * @author Vuong Minh <[email protected]>
19
 * @since 1.0
20
 * @deprecated since 1.0.2 we use `yiiviet\payment\HashDataSignature` instead.
21
 */
22
class DataSignature extends BaseDataSignature
23
{
24
25
    /**
26
     * @var string
27
     */
28
    public $hashSecret;
29
30
    /**
31
     * @var string
32
     */
33
    public $hashAlgo;
34
35
    /**
36
     * @inheritdoc
37
     * @throws InvalidConfigException
38
     */
39
    public function generate(): string
40
    {
41
        if ($this->hashSecret === null) {
42
            throw new InvalidConfigException('Property `hashSecret` must be set!');
43
        } elseif ($this->hashAlgo === null) {
44
            throw new InvalidConfigException('Property `hashAlgo` must be set!');
45
        }
46
47
        return hash($this->hashAlgo, $this->hashSecret . $this->getData());
48
    }
49
50
    /**
51
     * @throws InvalidConfigException
52
     * @inheritdoc
53
     */
54
    public function validate(string $expect): bool
55
    {
56
        $actual = $this->generate();
57
58
        return strcasecmp($expect, $actual) === 0;
59
    }
60
61
}
62