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 |
||
11 | class ProductWishList extends DataObject implements PermissionProvider, Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface, ManageableDataObjectInterface |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private static $db = [ |
||
18 | 'Title' => 'Varchar(100)', |
||
19 | 'Private' => 'Boolean', |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private static $has_one = [ |
||
26 | 'Member' => 'Member', |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | */ |
||
32 | 10 | public function onBeforeWrite() |
|
40 | |||
41 | /** |
||
42 | * @param null $params |
||
43 | * |
||
44 | * @return FieldList |
||
45 | */ |
||
46 | 1 | public function getFrontEndFields($params = null) |
|
60 | |||
61 | /** |
||
62 | * @param bool $showCancel |
||
63 | * |
||
64 | * @return FieldList |
||
65 | */ |
||
66 | 1 | public function getFrontEndActions($showCancel = false) |
|
82 | |||
83 | /** |
||
84 | * @return RequiredFields |
||
85 | */ |
||
86 | 1 | public function getFrontEndRequiredFields() |
|
96 | |||
97 | /** |
||
98 | * @return bool |
||
99 | */ |
||
100 | 1 | public function getIsEditing() |
|
106 | |||
107 | /** |
||
108 | * set ParentPage for ViewableDataobject |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getParentPage() |
||
117 | |||
118 | /** |
||
119 | * @return String|bool |
||
120 | */ |
||
121 | public function getUpdateLink() |
||
125 | |||
126 | /** |
||
127 | * set ViewAction for ViewableDataobject |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | 1 | public function getViewAction() |
|
135 | |||
136 | /** |
||
137 | * @return array |
||
138 | */ |
||
139 | 1 | public function providePermissions() |
|
160 | |||
161 | /** |
||
162 | * @param Member|null $member |
||
163 | * |
||
164 | * @return bool|int |
||
165 | */ |
||
166 | 1 | View Code Duplication | public function canEdit($member = null) |
173 | |||
174 | /** |
||
175 | * @param Member|null $member |
||
176 | * |
||
177 | * @return bool|int |
||
178 | */ |
||
179 | 1 | View Code Duplication | public function canDelete($member = null) |
186 | |||
187 | /** |
||
188 | * @param Member|null $member |
||
189 | * |
||
190 | * @return bool|int |
||
191 | */ |
||
192 | 1 | public function canCreate($member = null) |
|
196 | |||
197 | /** |
||
198 | * @param Member|null $member |
||
199 | * |
||
200 | * @return bool |
||
201 | */ |
||
202 | 2 | View Code Duplication | public function canView($member = null) |
209 | |||
210 | } |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.