MagicPropertiesTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 64.86 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 24
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
trait MagicPropertiesTrait
17
{
18
    /**
19
     * @inheritdoc
20
     * @throws \yii\base\UnknownPropertyException
21
     */
22 View Code Duplication
    public function __get($name)
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...
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 View Code Duplication
    public function __set($name, $value)
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...
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