Passed
Push — master ( 6b7895...39c748 )
by Nate
03:35
created

ElementWithHandle::rules()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
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.1.0
10
 */
11
12
namespace flipbox\spark\elements;
13
14
use Craft;
15
use craft\base\Element as BaseElement;
16
use craft\validators\HandleValidator;
17
use flipbox\spark\helpers\ElementHelper;
18
19
/**
20
 * Class ElementWithHandle
21
 * @package flipbox\spark\elements
22
 *
23
 * @property $handle
24
 *
25
 */
26
abstract class ElementWithHandle extends Element implements interfaces\ElementWithHande
27
{
28
29
    /**
30
     * @var string Handle
31
     */
32
    private $_handle;
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function getHandle(): string
38
    {
39
        return $this->_handle;
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function setHandle(string $handle)
46
    {
47
        $this->_handle = $handle;
48
        return $this;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function attributes()
55
    {
56
57
        return array_merge(
58
            parent::attributes(),
59
            [
60
                'handle'
61
            ]
62
        );
63
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function attributeLabels()
70
    {
71
72
        return array_merge(
73
            parent::attributes(),
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (attributes() instead of attributeLabels()). Are you sure this is correct? If so, you might want to change this to $this->attributes().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
74
            [
75
                'handle' => Craft::t('app', 'Handle'),
76
            ]
77
        );
78
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84
    public function rules()
85
    {
86
87
        return [
88
            [
89
                [
90
                    'handle'
91
                ],
92
                HandleValidator::class
93
            ],
94
            [
95
                [
96
                    'handle'
97
                ],
98
                'required'
99
            ],
100
            [
101
                [
102
                    'handle'
103
                ],
104
                'string',
105
                'max' => 255
106
            ],
107
            [
108
                [
109
                    'handle'
110
                ],
111
                'safe',
112
                'on' => [
113
                    ElementHelper::SCENARIO_DEFAULT
114
                ]
115
            ]
116
        ];
117
    }
118
119
}
120