Passed
Push — master ( 39c748...16551a )
by Nate
06:42
created

ModelWithHandle   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 66
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B rules() 38 38 1
A attributeLabels() 11 11 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
/**
4
 * @package    Spark
5
 * @author     Flipbox Factory <[email protected]>
6
 * @copyright  2010-2016 Flipbox Digital Limited
7
 * @license    https://github.com/flipbox/spark/blob/master/LICENSE
8
 * @link       https://github.com/flipbox/spark
9
 * @since      Class available since Release 1.0.0
10
 */
11
12
namespace flipbox\spark\models;
13
14
use Craft;
15
use craft\validators\HandleValidator;
16
use flipbox\spark\helpers\ModelHelper;
17
18 View Code Duplication
abstract class ModelWithHandle extends Model
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...
19
{
20
21
    /**
22
     * @var string Handle
23
     */
24
    public $handle;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function rules()
30
    {
31
32
        return array_merge(
33
            parent::rules(),
34
            [
35
                [
36
                    [
37
                        'handle'
38
                    ],
39
                    HandleValidator::class
40
                ],
41
                [
42
                    [
43
                        'handle'
44
                    ],
45
                    'required'
46
                ],
47
                [
48
                    [
49
                        'handle'
50
                    ],
51
                    'string',
52
                    'max' => 255
53
                ],
54
                [
55
                    [
56
                        'handle'
57
                    ],
58
                    'safe',
59
                    'on' => [
60
                        ModelHelper::SCENARIO_DEFAULT
61
                    ]
62
                ]
63
            ]
64
        );
65
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function attributeLabels()
72
    {
73
74
        return array_merge(
75
            parent::attributeLabels(),
76
            [
77
                'handle' => Craft::t('app', 'Handle')
78
            ]
79
        );
80
81
    }
82
83
}
84