Completed
Push — master ( 4b202c...dc308f )
by Vuong
02:05
created

DataSignature   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 40
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() 10 10 3
A validate() 6 6 1

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\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 View Code Duplication
class DataSignature extends BaseDataSignature
0 ignored issues
show
Duplication introduced by
This class 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...
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