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 |
||
| 36 | View Code Duplication | class EavAttributeOptionValueLoader implements LoaderInterface |
|
|
|
|||
| 37 | { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The attribute option values. |
||
| 41 | * |
||
| 42 | * @var array |
||
| 43 | */ |
||
| 44 | protected $eavAttributeOptionValues = array(); |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Construct that initializes the iterator with the import processor instance. |
||
| 48 | * |
||
| 49 | * @param \TechDivision\Import\Services\ImportProcessorInterface $importProcessor The import processor instance |
||
| 50 | */ |
||
| 51 | public function __construct(ImportProcessorInterface $importProcessor) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Loads and returns data the custom validation data. |
||
| 68 | * |
||
| 69 | * @param \TechDivision\Import\Configuration\ParamsConfigurationInterface $configuration The configuration instance to load the validations from |
||
| 70 | * |
||
| 71 | * @return \ArrayAccess The array with the data |
||
| 72 | */ |
||
| 73 | public function load(SubjectConfigurationInterface $configuration = null) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Return's the import processor instance. |
||
| 90 | * |
||
| 91 | * @return \TechDivision\Import\Services\ImportProcessorInterface The processor instance |
||
| 92 | */ |
||
| 93 | protected function getImportProcessor() |
||
| 97 | } |
||
| 98 |
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.