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 |
||
16 | View Code Duplication | class UpdateLeadStatus implements |
|
|
|||
17 | Migration, |
||
18 | ContainerAwareInterface, |
||
19 | OrderedMigrationInterface |
||
20 | { |
||
21 | /** @var ContainerInterface */ |
||
22 | protected $container; |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function getOrder() |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function setContainer(ContainerInterface $container = null) |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function up(Schema $schema, QueryBag $queries) |
||
69 | |||
70 | /** |
||
71 | * @param QueryBag $queries |
||
72 | * @param array $statuses |
||
73 | * @param int $priority |
||
74 | */ |
||
75 | protected function updateLeadStatusTable($queries, $statuses, $priority) |
||
94 | |||
95 | /** |
||
96 | * @param QueryBag $queries |
||
97 | * @param array $statuses |
||
98 | */ |
||
99 | protected function updateLeadTable($queries, $statuses) |
||
112 | |||
113 | /** |
||
114 | * @param array $rows |
||
115 | * @param string $key |
||
116 | * @param string $value |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | protected function buildOneDimensionArray($rows, $key, $value) |
||
130 | } |
||
131 |
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.