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 |
||
26 | abstract class AssetFormFactory implements FormFactory |
||
27 | { |
||
28 | use Extensible; |
||
29 | use Injectable; |
||
30 | use Configurable; |
||
31 | |||
32 | /** |
||
33 | * Insert into HTML content area |
||
34 | */ |
||
35 | const TYPE_INSERT = 'insert'; |
||
36 | |||
37 | /** |
||
38 | * Select file by ID only |
||
39 | */ |
||
40 | const TYPE_SELECT = 'select'; |
||
41 | |||
42 | /** |
||
43 | * Edit form: Default |
||
44 | */ |
||
45 | const TYPE_ADMIN = 'admin'; |
||
46 | |||
47 | public function __construct() |
||
51 | |||
52 | /** |
||
53 | * @param RequestHandler $controller |
||
54 | * @param string $name |
||
55 | * @param array $context |
||
56 | * @return Form |
||
57 | */ |
||
58 | public function getForm(RequestHandler $controller = null, $name = FormFactory::DEFAULT_NAME, $context = []) |
||
90 | |||
91 | /** |
||
92 | * Get the validator for the form to be built |
||
93 | * |
||
94 | * @param RequestHandler $controller |
||
95 | * @param $formName |
||
96 | * @param $context |
||
97 | * @return RequiredFields |
||
98 | */ |
||
99 | protected function getValidator(RequestHandler $controller = null, $formName, $context = []) |
||
105 | |||
106 | /** |
||
107 | * Get form type from 'type' context |
||
108 | * |
||
109 | * @param array $context |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function getFormType($context) |
||
116 | |||
117 | /** |
||
118 | * Gets the main tabs for the file edit form |
||
119 | * |
||
120 | * @param File $record |
||
121 | * @param array $context |
||
122 | * @return TabSet |
||
123 | */ |
||
124 | protected function getFormFieldTabs($record, $context = []) |
||
134 | |||
135 | /** |
||
136 | * @param File $record |
||
137 | * @return FormAction |
||
138 | */ |
||
139 | View Code Duplication | protected function getSaveAction($record) |
|
147 | |||
148 | /** |
||
149 | * Get delete action, if this record is deletable |
||
150 | * |
||
151 | * @param File $record |
||
152 | * @return FormAction |
||
153 | */ |
||
154 | View Code Duplication | protected function getDeleteAction($record) |
|
164 | |||
165 | /** |
||
166 | * @param RequestHandler $controller |
||
167 | * @param $formName |
||
168 | * @param array $context |
||
169 | * @return FieldList |
||
170 | */ |
||
171 | protected function getFormActions(RequestHandler $controller = null, $formName, $context = []) |
||
187 | |||
188 | /** |
||
189 | * Get fields for this form |
||
190 | * |
||
191 | * @param RequestHandler $controller |
||
192 | * @param string $formName |
||
193 | * @param array $context |
||
194 | * @return FieldList |
||
195 | */ |
||
196 | protected function getFormFields(RequestHandler $controller = null, $formName, $context = []) |
||
220 | |||
221 | /** |
||
222 | * Build popup menu |
||
223 | * |
||
224 | * @param File $record |
||
225 | * @return PopoverField |
||
226 | */ |
||
227 | protected function getPopoverMenu($record) |
||
242 | |||
243 | /** |
||
244 | * Get actions that go into the Popover menu |
||
245 | * |
||
246 | * @param File $record |
||
247 | * @return array |
||
248 | */ |
||
249 | protected function getPopoverActions($record) |
||
258 | |||
259 | /** |
||
260 | * Build "details" formfield tab |
||
261 | * |
||
262 | * @param File $record |
||
263 | * @param array $context |
||
264 | * @return Tab |
||
265 | */ |
||
266 | protected function getFormFieldDetailsTab($record, $context = []) |
||
273 | |||
274 | /** |
||
275 | * Build security tab |
||
276 | * |
||
277 | * @param File $record |
||
278 | * @param array $context |
||
279 | * @return Tab |
||
280 | */ |
||
281 | protected function getFormFieldSecurityTab($record, $context = []) |
||
320 | |||
321 | public function getRequiredContext() |
||
325 | } |
||
326 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.