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 namespace Mascame\Artificer\Fields; |
||
6 | class Field extends \Mascame\Formality\Field\Field |
||
7 | { |
||
8 | use Filterable; |
||
9 | |||
10 | /** |
||
11 | * @var null |
||
12 | */ |
||
13 | public $value; |
||
14 | |||
15 | public static $widgets = array(); |
||
16 | /** |
||
17 | * @var FieldOptions |
||
18 | */ |
||
19 | public $options; |
||
20 | |||
21 | /** |
||
22 | * @var FieldRelation |
||
23 | */ |
||
24 | public $relation = null; |
||
25 | |||
26 | /** |
||
27 | * Sometimes ajax limits output, setting this to true will return all |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | public $showFullField = false; |
||
32 | |||
33 | /** |
||
34 | * @param $name |
||
35 | * @param null $value |
||
36 | * @param $modelName |
||
37 | * @param $relation |
||
38 | */ |
||
39 | public function __construct($typeClass, $name, $value = null, $relation) |
||
49 | |||
50 | /** |
||
51 | * @param $widget |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function addWidget(AbstractWidget $widget) |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Used to load custom assets, widgets, ... |
||
68 | * |
||
69 | */ |
||
70 | public function boot() |
||
86 | |||
87 | |||
88 | /** |
||
89 | * @return null |
||
90 | */ |
||
91 | public function show() |
||
95 | |||
96 | /** |
||
97 | * @param null $value |
||
98 | * @return null |
||
99 | */ |
||
100 | // public function display($value = null) |
||
101 | // { |
||
102 | // $this->value = $this->getValue($value); |
||
103 | // |
||
104 | // return $this->show(); |
||
105 | // } |
||
106 | |||
107 | |||
108 | public function setValue($value) { |
||
111 | |||
112 | /** |
||
113 | * @param null $value |
||
114 | * @return null |
||
115 | */ |
||
116 | public function getValue($value = null) |
||
130 | |||
131 | /** |
||
132 | * @return bool|mixed|null|string |
||
133 | */ |
||
134 | public function output() |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @return string |
||
146 | */ |
||
147 | public function hidden() |
||
151 | |||
152 | /** |
||
153 | * @param $array |
||
154 | * @return bool |
||
155 | */ |
||
156 | protected function isAll($array) |
||
160 | |||
161 | /** |
||
162 | * @param string $list |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function isListed($list = 'show') |
||
179 | |||
180 | |||
181 | /** |
||
182 | * @return bool |
||
183 | */ |
||
184 | public function isHiddenList() |
||
188 | |||
189 | |||
190 | /** |
||
191 | * @param $value |
||
192 | * @param $array |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function isInArray($value, $array) |
||
199 | |||
200 | |||
201 | /** |
||
202 | * @return string |
||
203 | */ |
||
204 | public function guarded() |
||
208 | |||
209 | /** |
||
210 | * @return bool |
||
211 | */ |
||
212 | View Code Duplication | public function isGuarded() |
|
220 | |||
221 | /** |
||
222 | * @return bool |
||
223 | */ |
||
224 | View Code Duplication | public function isHidden() |
|
232 | |||
233 | /** |
||
234 | * @return bool |
||
235 | */ |
||
236 | public function isRelation() |
||
240 | |||
241 | public static function get($name) |
||
245 | |||
246 | public function __call($method, $args) { |
||
253 | } |
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.