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 | class EnhancedSelectionConverter implements Converter |
||
14 | { |
||
15 | /** |
||
16 | * Converts data from $value to $storageFieldValue. |
||
17 | * |
||
18 | * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value |
||
19 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue |
||
20 | */ |
||
21 | public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue) |
||
24 | |||
25 | /** |
||
26 | * Converts data from $value to $fieldValue. |
||
27 | * |
||
28 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value |
||
29 | * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue |
||
30 | */ |
||
31 | public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) |
||
34 | |||
35 | /** |
||
36 | * Converts field definition data in $fieldDef into $storageFieldDef. |
||
37 | * |
||
38 | * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
||
39 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
||
40 | */ |
||
41 | public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef) |
||
91 | |||
92 | /** |
||
93 | * Converts field definition data in $storageDef into $fieldDef. |
||
94 | * |
||
95 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
||
96 | * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
||
97 | */ |
||
98 | public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef) |
||
140 | |||
141 | /** |
||
142 | * Returns the name of the index column in the attribute table. |
||
143 | * |
||
144 | * Returns the name of the index column the datatype uses, which is either |
||
145 | * "sort_key_int" or "sort_key_string". This column is then used for |
||
146 | * filtering and sorting for this type. |
||
147 | * |
||
148 | * If the indexing is not supported, this method must return false. |
||
149 | * |
||
150 | * @return string|false |
||
151 | */ |
||
152 | public function getIndexColumn() |
||
156 | } |
||
157 |
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.