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 |
||
13 | View Code Duplication | class CommentsGridFieldSpamAction implements GridField_ColumnProvider, GridField_ActionProvider, GridField_ActionMenuItem |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | public function augmentColumns($gridField, &$columns) |
||
24 | |||
25 | public function getTitle($gridField, $record, $columnName) |
||
29 | |||
30 | public function getExtraData($gridField, $record, $columnName) |
||
41 | |||
42 | public function getGroup($gridField, $record, $columnName) |
||
48 | |||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function getColumnAttributes($gridField, $record, $columnName) |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function getColumnMetadata($gridField, $columnName) |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function getColumnsHandled($gridField) |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function getColumnContent($gridField, $record, $columnName) |
||
89 | |||
90 | /** |
||
91 | * Returns the FormAction object, used by other methods to get properties |
||
92 | * |
||
93 | * @return GridField_FormAction |
||
94 | */ |
||
95 | public function getSpamAction($gridField, $record, $columnName) |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getActions($gridField) |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function handleAction(GridField $gridField, $actionName, $arguments, $data) |
||
138 | } |
||
139 |
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.