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

MagicPropertiesTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 37
loc 37
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 12 12 3
A __set() 12 12 3

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 Yii2VN
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\payment\vnpayment;
9
10
/**
11
 * Trait MagicPropertiesTrait là trait bổ sung phương thức getter và setter nhầm giảm hóa sự lập đi lập lại của prefix `vnp_`
12
 *
13
 * @author Vuong Minh <[email protected]>
14
 * @since 1.0
15
 */
16 View Code Duplication
trait MagicPropertiesTrait
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...
17
{
18
    /**
19
     * @inheritdoc
20
     * @throws \yii\base\UnknownPropertyException
21
     */
22
    public function __get($name)
23
    {
24
        try {
25
            return parent::__get($name);
26
        } catch (\yii\base\UnknownPropertyException $e) {
27
            if (isset($this["vnp_$name"])) {
28
                return $this["vnp_$name"];
29
            } else {
30
                throw $e;
31
            }
32
        }
33
    }
34
35
    /**
36
     * @inheritdoc
37
     * @throws \yii\base\UnknownPropertyException
38
     */
39
    public function __set($name, $value)
40
    {
41
        try {
42
            parent::__set($name, $value);
43
        } catch (\yii\base\UnknownPropertyException $e) {
44
            if (isset($this["vnp_$name"])) {
45
                $this["vnp_$name"] = $value;
46
            } else {
47
                throw $e;
48
            }
49
        }
50
    }
51
52
}
53