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 |
||
| 22 | class DateConverter implements Converter |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Factory for current class. |
||
| 26 | * |
||
| 27 | * Note: Class should instead be configured as service if it gains dependencies. |
||
| 28 | * |
||
| 29 | * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\DateConverter |
||
| 30 | */ |
||
| 31 | public static function create() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Converts data from $value to $storageFieldValue. |
||
| 38 | * |
||
| 39 | * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $value |
||
| 40 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $storageFieldValue |
||
| 41 | */ |
||
| 42 | public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Converts data from $value to $fieldValue. |
||
| 50 | * |
||
| 51 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue $value |
||
| 52 | * @param \eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Converts field definition data in $fieldDef into $storageFieldDef. |
||
| 69 | * |
||
| 70 | * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
||
| 71 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
||
| 72 | */ |
||
| 73 | public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Converts field definition data in $storageDef into $fieldDef. |
||
| 80 | * |
||
| 81 | * @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef |
||
| 82 | * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef |
||
| 83 | */ |
||
| 84 | public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Returns the name of the index column in the attribute table. |
||
| 110 | * |
||
| 111 | * Returns the name of the index column the datatype uses, which is either |
||
| 112 | * "sort_key_int" or "sort_key_string". This column is then used for |
||
| 113 | * filtering and sorting for this type. |
||
| 114 | * |
||
| 115 | * @return string |
||
| 116 | */ |
||
| 117 | public function getIndexColumn() |
||
| 121 | } |
||
| 122 |