Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

Nip_Form_Button_Abstract   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 225
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 28
lcom 2
cbo 2
dl 30
loc 225
c 0
b 0
f 0
ccs 0
cts 75
cp 0
rs 10

24 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 5 1
A setId() 0 5 1
A render() 0 3 1
A getAttribs() 0 3 1
A setForm() 0 5 1
A getId() 0 3 1
A setName() 0 5 1
A getForm() 0 3 1
A setAttrib() 0 6 1
A init() 0 3 1
A setLabel() 0 5 1
A addAttribs() 0 7 2
A getValue() 0 3 1
A getType() 0 3 1
A getName() 0 3 1
A delAttrib() 0 6 1
A removeAttrib() 0 9 2
A clearAttribs() 0 5 1
A setAttribs() 0 5 1
A addClass() 0 10 2
A getLabel() 0 3 1
A __construct() 0 4 1
A getRenderer() 0 3 1
A getAttrib() 0 8 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
3
use Nip\Form\AbstractForm;
4
5
abstract class Nip_Form_Button_Abstract
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    protected $_form;
8
    protected $_attribs;
9
    protected $_uniqueID;
10
11
    protected $_type = 'abstract';
12
13
    public function __construct($form)
14
    {
15
        $this->setForm($form);
16
        $this->init();
17
    }
18
19
    public function init()
20
    {
21
        $this->addClass('btn', 'btn-primary');
22
    }
23
24
    public function addClass()
25
    {
26
        $classes = func_get_args();
27
        if (is_array($classes)) {
0 ignored issues
show
introduced by
The condition is_array($classes) is always true.
Loading history...
28
            $oldClasses = explode(' ', $this->getAttrib('class'));
29
            $classes = array_merge($classes, $oldClasses);
30
            $this->setAttrib('class', implode(' ', $classes));
31
        }
32
33
        return $this;
34
    }
35
36
    /**
37
     * @param string $key
38
     *
39
     * @return string
40
     */
41
    public function getAttrib($key)
42
    {
43
        $key = (string) $key;
44
        if (!isset($this->_attribs[$key])) {
45
            return null;
46
        }
47
48
        return $this->_attribs[$key];
49
    }
50
51
    /**
52
     * @return Nip_Form_Button_Abstract
53
     */
54
    public function setAttrib($key, $value)
55
    {
56
        $key = (string) $key;
57
        $this->_attribs[$key] = $value;
58
59
        return $this;
60
    }
61
62
    public function setId($id)
63
    {
64
        $this->setAttrib('id', $id);
65
66
        return $this;
67
    }
68
69
    public function getId()
70
    {
71
        return $this->getAttrib('id');
72
    }
73
74
    public function setName($name)
75
    {
76
        $this->setAttrib('name', $name);
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getName()
85
    {
86
        return $this->getAttrib('name');
87
    }
88
89
    /**
90
     * @param string $label
91
     * @return $this
92
     */
93
    public function setLabel($label)
94
    {
95
        $this->setAttrib('label', $label);
96
97
        return $this;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getLabel()
104
    {
105
        return $this->getAttrib('label');
106
    }
107
108
    /**
109
     * @param $value
110
     * @return $this
111
     */
112
    public function setValue($value)
113
    {
114
        $this->setAttrib('value', $value);
115
116
        return $this;
117
    }
118
119
    /**
120
     * @param string $requester
121
     * @return string
122
     */
123
    public function getValue($requester = 'abstract')
0 ignored issues
show
Unused Code introduced by
The parameter $requester is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

123
    public function getValue(/** @scrutinizer ignore-unused */ $requester = 'abstract')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
124
    {
125
        return $this->getAttrib('value');
126
    }
127
128
    /**
129
     * @param $key
130
     * @return bool
131
     */
132
    public function delAttrib($key)
133
    {
134
        $key = (string) $key;
135
        unset($this->_attribs[$key]);
136
137
        return true;
138
    }
139
140
    public function getAttribs()
141
    {
142
        return $this->_attribs;
143
    }
144
145
    /**
146
     * @param  array $attribs
147
     * @return Nip_Form_Button_Abstract
148
     */
149
    public function setAttribs(array $attribs)
150
    {
151
        $this->clearAttribs();
152
153
        return $this->addAttribs($attribs);
154
    }
155
156
    /**
157
     * @return Nip_Form_Button_Abstract
158
     */
159
    public function clearAttribs()
160
    {
161
        $this->_attribs = [];
162
163
        return $this;
164
    }
165
166
    /**
167
     * @param  array $attribs
168
     * @return Nip_Form_Button_Abstract
169
     */
170
    public function addAttribs(array $attribs)
171
    {
172
        foreach ($attribs as $key => $value) {
173
            $this->setAttrib($key, $value);
174
        }
175
176
        return $this;
177
    }
178
179
    /**
180
     * @return bool
181
     */
182
    public function removeAttrib($key)
183
    {
184
        if (isset($this->_attribs[$key])) {
185
            unset($this->_attribs[$key]);
186
187
            return true;
188
        }
189
190
        return false;
191
    }
192
193
    public function render()
194
    {
195
        return $this->getRenderer()->render($this);
196
    }
197
198
    public function getRenderer()
199
    {
200
        return $this->getForm()->getRenderer()->getButtonRenderer($this);
201
    }
202
203
    /**
204
     * @return AbstractForm
205
     */
206
    public function getForm()
207
    {
208
        return $this->_form;
209
    }
210
211
    /**
212
     * @param AbstractForm $form
213
     * @return $this
214
     */
215
    public function setForm(AbstractForm $form)
216
    {
217
        $this->_form = $form;
218
219
        return $this;
220
    }
221
222
    /**
223
     * @return string
224
     */
225
    public function getType()
226
    {
227
        return $this->_type;
228
    }
229
}
230