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 |
||
| 17 | class ImageAssetConverter implements Converter |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Converts data from $value to $storageFieldValue. |
||
| 21 | * |
||
| 22 | * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value |
||
| 23 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue |
||
| 24 | */ |
||
| 25 | public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Converts data from $value to $fieldValue. |
||
| 38 | * |
||
| 39 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value |
||
| 40 | * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue |
||
| 41 | */ |
||
| 42 | View Code Duplication | public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Converts field definition data in $fieldDef into $storageFieldDef. |
||
| 53 | * |
||
| 54 | * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
||
| 55 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
||
| 56 | */ |
||
| 57 | public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Converts field definition data in $storageDef into $fieldDef. |
||
| 63 | * |
||
| 64 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
||
| 65 | * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
||
| 66 | */ |
||
| 67 | public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Returns the name of the index column in the attribute table. |
||
| 73 | * |
||
| 74 | * Returns the name of the index column the datatype uses, which is either |
||
| 75 | * "sort_key_int" or "sort_key_string". This column is then used for |
||
| 76 | * filtering and sorting for this type. |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public function getIndexColumn() |
||
| 84 | } |
||
| 85 |