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 |
||
11 | class UpdateReportQuery extends ParametrizedMigrationQuery |
||
12 | { |
||
13 | /** |
||
14 | * {@inheritdoc} |
||
15 | */ |
||
16 | public function getDescription() |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function execute(LoggerInterface $logger) |
||
31 | |||
32 | /** |
||
33 | * @param LoggerInterface $logger |
||
34 | * @param bool $dryRun |
||
35 | */ |
||
36 | public function doExecute(LoggerInterface $logger, $dryRun = false) |
||
41 | |||
42 | /** |
||
43 | * @param LoggerInterface $logger |
||
44 | * @param $dryRun |
||
45 | * @param $def |
||
46 | * @param $row |
||
47 | * @throws \Doctrine\DBAL\DBALException |
||
48 | */ |
||
49 | protected function updateReport(LoggerInterface $logger, $dryRun, $def, $row) |
||
54 | |||
55 | /** |
||
56 | * @param LoggerInterface $logger |
||
57 | * @param $dryRun |
||
58 | * @param $def |
||
59 | * @param $row |
||
60 | * @throws \Doctrine\DBAL\DBALException |
||
61 | */ |
||
62 | protected function updateSegment(LoggerInterface $logger, $dryRun, $def, $row) |
||
67 | |||
68 | /** |
||
69 | * @param LoggerInterface $logger |
||
70 | * @param $dryRun |
||
71 | */ |
||
72 | View Code Duplication | protected function migrateReport(LoggerInterface $logger, $dryRun) |
|
87 | |||
88 | /** |
||
89 | * @param LoggerInterface $logger |
||
90 | * @param $dryRun |
||
91 | */ |
||
92 | View Code Duplication | protected function migrateSegment(LoggerInterface $logger, $dryRun) |
|
107 | |||
108 | /** |
||
109 | * @param LoggerInterface $logger |
||
110 | * @param $dryRun |
||
111 | * @param $def |
||
112 | * @param $row |
||
113 | * @param $className |
||
114 | * @param $oldField |
||
115 | * @param $newField |
||
116 | */ |
||
117 | View Code Duplication | protected function fixSegmentDefs(LoggerInterface $logger, $dryRun, $def, $row, $className, $oldField, $newField) |
|
137 | |||
138 | /** |
||
139 | * @param LoggerInterface $logger |
||
140 | * @param $dryRun |
||
141 | * @param $def |
||
142 | * @param $row |
||
143 | * @param $className |
||
144 | * @param $oldField |
||
145 | * @param $newField |
||
146 | */ |
||
147 | protected function fixReportDefs(LoggerInterface $logger, $dryRun, $def, $row, $className, $oldField, $newField) |
||
172 | |||
173 | /** |
||
174 | * @param LoggerInterface $logger |
||
175 | * @param $dryRun |
||
176 | * @param $def |
||
177 | * @param $row |
||
178 | * @param $query |
||
179 | * @throws \Doctrine\DBAL\DBALException |
||
180 | */ |
||
181 | View Code Duplication | protected function executeQuery(LoggerInterface $logger, $dryRun, $def, $row, $query) |
|
190 | |||
191 | /** |
||
192 | * @param $def |
||
193 | * @param $row |
||
194 | * @param $className |
||
195 | * @param $oldField |
||
196 | * @param $newField |
||
197 | * @param $field |
||
198 | * @param $key |
||
199 | * @return mixed |
||
200 | */ |
||
201 | View Code Duplication | protected function processFilterDefinition($def, $row, $className, $oldField, $newField, $field, $key) |
|
212 | |||
213 | /** |
||
214 | * @param $def |
||
215 | * @param $field |
||
216 | * @param $key |
||
217 | * @return array |
||
218 | */ |
||
219 | View Code Duplication | protected function fixFilterCriterion($def, $field, $key) |
|
233 | } |
||
234 |
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.