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 |
||
23 | abstract class AssetFormFactory implements FormFactory |
||
24 | { |
||
25 | use Extensible; |
||
26 | use Injectable; |
||
27 | use Configurable; |
||
28 | |||
29 | /** |
||
30 | * Insert into HTML content area |
||
31 | */ |
||
32 | const TYPE_INSERT = 'insert'; |
||
33 | |||
34 | /** |
||
35 | * Select file by ID only |
||
36 | */ |
||
37 | const TYPE_SELECT = 'select'; |
||
38 | |||
39 | /** |
||
40 | * Edit form: Default |
||
41 | */ |
||
42 | const TYPE_ADMIN = 'admin'; |
||
43 | |||
44 | public function __construct() |
||
48 | |||
49 | public function getForm(Controller $controller, $name = FormFactory::DEFAULT_NAME, $context = []) |
||
73 | |||
74 | /** |
||
75 | * Get the validator for the form to be built |
||
76 | * |
||
77 | * @param $controller |
||
78 | * @param $formName |
||
79 | * @param $context |
||
80 | * @return RequiredFields |
||
81 | */ |
||
82 | protected function getValidator(Controller $controller, $formName, $context = []) |
||
88 | |||
89 | /** |
||
90 | * Get form type from 'type' context |
||
91 | * |
||
92 | * @param array $context |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function getFormType($context) |
||
99 | |||
100 | /** |
||
101 | * Gets the main tabs for the file edit form |
||
102 | * |
||
103 | * @param File $record |
||
104 | * @return TabSet |
||
105 | */ |
||
106 | protected function getFormFieldTabs($record, $context = []) |
||
112 | |||
113 | /** |
||
114 | * @param File $record |
||
115 | * @return FormAction |
||
116 | */ |
||
117 | View Code Duplication | protected function getSaveAction($record) |
|
125 | |||
126 | /** |
||
127 | * Get delete action, if this record is deletable |
||
128 | * |
||
129 | * @param File $record |
||
130 | * @return FormAction |
||
131 | */ |
||
132 | View Code Duplication | protected function getDeleteAction($record) |
|
142 | |||
143 | /** |
||
144 | * @param Controller $controller |
||
145 | * @param $formName |
||
146 | * @param array $context |
||
147 | * @return FieldList |
||
148 | */ |
||
149 | protected function getFormActions(Controller $controller, $formName, $context = []) |
||
165 | |||
166 | /** |
||
167 | * Get fields for this form |
||
168 | * |
||
169 | * @param Controller $controller |
||
170 | * @param string $formName |
||
171 | * @param array $context |
||
172 | * @return FieldList |
||
173 | */ |
||
174 | protected function getFormFields(Controller $controller, $formName, $context = []) |
||
198 | |||
199 | /** |
||
200 | * Build popup menu |
||
201 | * |
||
202 | * @param File $record |
||
203 | * @return PopoverField |
||
204 | */ |
||
205 | protected function getPopoverMenu($record) |
||
219 | |||
220 | /** |
||
221 | * Get actions that go into the Popover menu |
||
222 | * |
||
223 | * @param $record |
||
224 | * @return array |
||
225 | */ |
||
226 | protected function getPopoverActions($record) |
||
232 | |||
233 | /** |
||
234 | * Build "details" formfield tab |
||
235 | * |
||
236 | * @param File $record |
||
237 | * @param array $context |
||
238 | * @return Tab |
||
239 | */ |
||
240 | protected function getFormFieldDetailsTab($record, $context = []) |
||
247 | |||
248 | public function getRequiredContext() |
||
252 | } |
||
253 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.