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 |
||
| 23 | abstract class QueryChecker |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Determines whether the query builder uses a HAVING clause. |
||
| 27 | * |
||
| 28 | * @param QueryBuilder $queryBuilder |
||
| 29 | * |
||
| 30 | * @return bool |
||
| 31 | */ |
||
| 32 | public static function hasHavingClause(QueryBuilder $queryBuilder) : bool |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Determines whether the query builder has any root entity with foreign key identifier. |
||
| 39 | * |
||
| 40 | * @param QueryBuilder $queryBuilder |
||
| 41 | * @param ManagerRegistry $managerRegistry |
||
| 42 | * |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | View Code Duplication | public static function hasRootEntityWithForeignKeyIdentifier(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry) : bool |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Determines whether the query builder has any composite identifier. |
||
| 62 | * |
||
| 63 | * @param QueryBuilder $queryBuilder |
||
| 64 | * @param ManagerRegistry $managerRegistry |
||
| 65 | * |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | View Code Duplication | public static function hasRootEntityWithCompositeIdentifier(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry) : bool |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Determines whether the query builder has the maximum number of results specified. |
||
| 85 | * |
||
| 86 | * @param QueryBuilder $queryBuilder |
||
| 87 | * |
||
| 88 | * @return bool |
||
| 89 | */ |
||
| 90 | public static function hasMaxResults(QueryBuilder $queryBuilder) : bool |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Determines whether the query builder has ORDER BY on entity joined through |
||
| 97 | * to-many association. |
||
| 98 | * |
||
| 99 | * @param QueryBuilder $queryBuilder |
||
| 100 | * @param ManagerRegistry $managerRegistry |
||
| 101 | * |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry) : bool |
||
| 150 | } |
||
| 151 |
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.