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 |
||
| 13 | View Code Duplication | class FamilyProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
|
|
|||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var FamilyNormalizer |
||
| 17 | */ |
||
| 18 | protected $familyNormalizer; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $globalContext = array(); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param FamilyNormalizer $familyNormalizer The entity manager |
||
| 27 | */ |
||
| 28 | public function __construct(FamilyNormalizer $familyNormalizer) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param mixed $family |
||
| 35 | * @return array|mixed |
||
| 36 | * @throws InvalidItemException |
||
| 37 | */ |
||
| 38 | public function process($family) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param Family $family |
||
| 45 | * @param array $context |
||
| 46 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
||
| 47 | * @throws InvalidItemException |
||
| 48 | */ |
||
| 49 | protected function normalizeFamily(Family $family, array $context) |
||
| 63 | |||
| 64 | public function getConfigurationFields() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param StepExecution $stepExecution |
||
| 71 | */ |
||
| 72 | public function setStepExecution(StepExecution $stepExecution) |
||
| 76 | } |
||
| 77 |
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.