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 |
||
| 8 | class EzImage extends FileFieldHandler implements FieldValueConverterInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Creates a value object to use as the field value when setting an image field type. |
||
| 12 | * |
||
| 13 | * @param array|string $fieldValue The path to the file or an array with 'path' and 'alt_text' keys |
||
| 14 | * @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration |
||
| 15 | * @return ImageValue |
||
| 16 | */ |
||
| 17 | public function hashToFieldValue($fieldValue, array $context = array()) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param \eZ\Publish\Core\FieldType\Image\Value $fieldValue |
||
| 56 | * @param array $context |
||
| 57 | * @return array |
||
| 58 | * |
||
| 59 | * @todo check out if this works in ezplatform |
||
| 60 | */ |
||
| 61 | View Code Duplication | public function fieldValueToHash($fieldValue, array $context = array()) |
|
| 69 | } |
||
| 70 |
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.