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 |
||
| 46 | class CircleRequestBuilder extends CoreRequestBuilder { |
||
| 47 | |||
| 48 | |||
| 49 | /** |
||
| 50 | * @return CoreQueryBuilder |
||
| 51 | */ |
||
| 52 | View Code Duplication | protected function getCircleInsertSql(): CoreQueryBuilder { |
|
| 59 | |||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $id |
||
| 63 | * |
||
| 64 | * @return CoreQueryBuilder |
||
| 65 | */ |
||
| 66 | protected function getCircleUpdateSql(): CoreQueryBuilder { |
||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * @return CoreQueryBuilder |
||
| 76 | */ |
||
| 77 | protected function getCircleSelectSql(): CoreQueryBuilder { |
||
| 89 | |||
| 90 | |||
| 91 | /** |
||
| 92 | * Base of the Sql Delete request |
||
| 93 | * |
||
| 94 | * @return CoreQueryBuilder |
||
| 95 | */ |
||
| 96 | protected function getCircleDeleteSql(): CoreQueryBuilder { |
||
| 102 | |||
| 103 | |||
| 104 | /** |
||
| 105 | * @param CoreQueryBuilder $qb |
||
| 106 | * |
||
| 107 | * @return Circle |
||
| 108 | * @throws CircleNotFoundException |
||
| 109 | */ |
||
| 110 | public function getItemFromRequest(CoreQueryBuilder $qb): Circle { |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param CoreQueryBuilder $qb |
||
| 123 | * |
||
| 124 | * @return Circle[] |
||
| 125 | */ |
||
| 126 | public function getItemsFromRequest(CoreQueryBuilder $qb): array { |
||
| 130 | |||
| 131 | } |
||
| 132 |
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.