Completed
Pull Request — master (#39)
by
unknown
05:32
created

Currency   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 102
Duplicated Lines 8.82 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 1
dl 9
loc 102
ccs 33
cts 33
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTagProperties() 0 8 1
B rules() 0 46 1
A getYmlBody() 0 4 1
A getYmlEndTag() 0 4 1
A getYmlStartTag() 9 9 2

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
namespace pastuhov\ymlcatalog\models;
3
4
class Currency extends BaseModel
5
{
6
    /**
7
     * @inheritdoc
8
     */
9
    public static $tag = 'currency';
10
11
    public $id;
12
    public $rate;
13
    public $plus;
14
15
    /**
16
     * @inheritdoc
17
     */
18
    public static function getTagProperties()
19
    {
20
        return [
21
            'id',
22
            'rate',
23
            'plus',
24
        ];
25
    }
26
27 9
    /**
28
     * @inheritdoc
29
     */
30
    public function rules()
31
    {
32 6
        return [
33 6
            [
34 6
                [
35 6
                    'id',
36 9
                    'rate',
37
                ],
38
                'required',
39 6
            ],
40 6
            [
41 6
                [
42 6
                    'rate',
43 6
                ],
44
                'string',
45
                'max' => 5,
46 6
            ],
47 6
            [
48 6
                [
49 6
                    'id',
50 6
                ],
51
                'string',
52
                'max' => 3,
53 6
            ],
54 6
            [
55 6
                [
56 6
                    'plus',
57
                ],
58
                'integer',
59 6
            ],
60 6
            [
61 6
                [
62
                    'id',
63 6
                ],
64 6
                'in',
65 6
                'range' => [
66 6
                    'RUR',
67 6
                    'RUB',
68
                    'UAH',
69 6
                    'KZT',
70 6
                    'USD',
71 6
                    'EUR'
72
                ],
73
            ],
74
        ];
75
    }
76
77 9
    /**
78
     * @inheritdoc
79 9
     */
80
    protected function getYmlBody()
81
    {
82
        return null;
83
    }
84
    
85
    /**
86
     * @return string
87
     */
88
    protected function getYmlEndTag()
89
    {
90
        return '';
91
    }
92
93
    /**
94
     * @return string
95
     */
96 View Code Duplication
    protected function getYmlStartTag()
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...
97
    {
98
        $string = '';
99
        if (static::$tag) {
100
            $string = '<' . static::$tag . $this->getYmlTagProperties() . ' />';
101
        }
102
103
        return $string;
104
    }
105
}
106