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 |
||
| 39 | View Code Duplication | class ImportAdapter implements ImportAdapterConfigurationInterface |
|
|
|
|||
| 40 | { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Trait that provides CSV configuration functionality. |
||
| 44 | * |
||
| 45 | * @var \TechDivision\Import\Configuration\Jms\CsvTrait |
||
| 46 | */ |
||
| 47 | use CsvTrait; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The import adapter's unique DI identifier. |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | * @Type("string") |
||
| 54 | */ |
||
| 55 | protected $id = DependencyInjectionKeys::IMPORT_ADAPTER_IMPORT_CSV_FACTORY; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The filesystem adapter configuration instance. |
||
| 59 | * |
||
| 60 | * @var \TechDivision\Import\Configuration\Subject\SerializerConfigurationInterface |
||
| 61 | * @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\Serializer") |
||
| 62 | * @SerializedName("serializer") |
||
| 63 | */ |
||
| 64 | protected $serializer; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Return's the import adapter's unique DI identifier |
||
| 68 | * |
||
| 69 | * @return string The import adapter's unique DI identifier |
||
| 70 | */ |
||
| 71 | public function getId() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Return's the serializer configuration instance. |
||
| 78 | * |
||
| 79 | * @return \TechDivision\Import\Configuration\Subject\SerializerConfigurationInterface The serializer configuration instance |
||
| 80 | */ |
||
| 81 | public function getSerializer() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Lifecycle callback that will be invoked after deserialization. |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | * @PostDeserialize |
||
| 91 | */ |
||
| 92 | public function postDeserialize() |
||
| 100 | } |
||
| 101 |
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.