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 | final class RSMQueryResult implements Result |
||
17 | { |
||
18 | private $em; |
||
19 | private $rsm; |
||
20 | private $qb; |
||
21 | private $queryBuilderResult; |
||
22 | |||
23 | /** |
||
24 | * @param EntityManagerInterface $em |
||
25 | * @param ResultSetMappingBuilder $rsm |
||
26 | * @param QueryBuilder $qb |
||
27 | * @param callable|null $countQueryBuilderModifier |
||
28 | 8 | */ |
|
29 | public function __construct(EntityManagerInterface $em, ResultSetMappingBuilder $rsm, QueryBuilder $qb, callable $countQueryBuilderModifier = null) |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | 5 | */ |
|
40 | View Code Duplication | public function take($offset, $limit) |
|
52 | 5 | ||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function count() |
||
60 | 3 | ||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function getIterator() |
||
68 | 3 | ||
69 | 3 | /** |
|
70 | * @return NativeQuery |
||
71 | 3 | */ |
|
72 | 2 | public function getQuery() |
|
76 | |||
77 | /** |
||
78 | * @param QueryBuilder $qb |
||
79 | * |
||
80 | * @return NativeQuery |
||
81 | */ |
||
82 | private function createQuery(QueryBuilder $qb) |
||
89 | } |
||
90 |
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.