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 |
||
| 40 | class RemoteRequestBuilder extends CoreRequestBuilder { |
||
| 41 | |||
| 42 | |||
| 43 | /** |
||
| 44 | * @return CoreQueryBuilder |
||
| 45 | */ |
||
| 46 | View Code Duplication | protected function getRemoteInsertSql(): CoreQueryBuilder { |
|
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * Base of the Sql Update request for Groups |
||
| 57 | * |
||
| 58 | * @return CoreQueryBuilder |
||
| 59 | */ |
||
| 60 | protected function getRemoteUpdateSql(): CoreQueryBuilder { |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * @return CoreQueryBuilder |
||
| 70 | */ |
||
| 71 | protected function getRemoteSelectSql(): CoreQueryBuilder { |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Base of the Sql Delete request |
||
| 84 | * |
||
| 85 | * @return CoreQueryBuilder |
||
| 86 | */ |
||
| 87 | protected function getRemoteDeleteSql(): CoreQueryBuilder { |
||
| 93 | |||
| 94 | |||
| 95 | /** |
||
| 96 | * @param CoreQueryBuilder $qb |
||
| 97 | * |
||
| 98 | * @return AppService |
||
| 99 | * @throws RowNotFoundException |
||
| 100 | */ |
||
| 101 | public function getItemFromRequest(CoreQueryBuilder $qb): AppService { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param CoreQueryBuilder $qb |
||
| 110 | * |
||
| 111 | * @return AppService[] |
||
| 112 | */ |
||
| 113 | public function getItemsFromRequest(CoreQueryBuilder $qb): array { |
||
| 117 | |||
| 118 | } |
||
| 119 |
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.