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 |
||
15 | class OrdersRepository extends EntityRepository |
||
16 | { |
||
17 | /** |
||
18 | * Renvoi les dernières commandes. |
||
19 | * |
||
20 | * @param integer $count Nombre d'élément à afficher |
||
21 | * @return array Query result |
||
22 | */ |
||
23 | public function getLastOrder($count) |
||
31 | |||
32 | /** |
||
33 | * Renvoi les dernières commandes. |
||
34 | * |
||
35 | * @param integer $count Nombre d'élément à afficher |
||
36 | * @return array Query result |
||
37 | */ |
||
38 | public function getLastDelivery($count) |
||
46 | |||
47 | /** |
||
48 | * Renvoi les dernières commandes. |
||
49 | * |
||
50 | * @param integer $count Nombre d'élément à afficher |
||
51 | * @return array Query result |
||
52 | */ |
||
53 | public function getLastInvoice($count) |
||
62 | |||
63 | /** |
||
64 | * Find Orders before delivering. |
||
65 | * |
||
66 | * @return \Doctrine\ORM\QueryBuilder |
||
67 | */ |
||
68 | View Code Duplication | public function findOrders() |
|
78 | |||
79 | /** |
||
80 | * Find Orders for delivering. |
||
81 | * |
||
82 | * @return \Doctrine\ORM\QueryBuilder |
||
83 | */ |
||
84 | View Code Duplication | public function findDeliveries() |
|
94 | |||
95 | /** |
||
96 | * Find Orders for billing. |
||
97 | * |
||
98 | * @return \Doctrine\ORM\QueryBuilder |
||
99 | */ |
||
100 | View Code Duplication | public function findInvoices() |
|
110 | } |
||
111 |
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.