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 |
||
14 | View Code Duplication | class AbstractArticleCategoryAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator |
|
|
|||
15 | { |
||
16 | /** |
||
17 | * @param EntityManagerInterface $em The entity manager |
||
18 | * @param AclHelper $aclHelper The ACL helper |
||
19 | */ |
||
20 | public function __construct(EntityManagerInterface $em, AclHelper $aclHelper) |
||
24 | |||
25 | /** |
||
26 | * Return current bundle name. |
||
27 | * |
||
28 | * @return string |
||
29 | */ |
||
30 | public function getBundleName() |
||
34 | |||
35 | /** |
||
36 | * Return current entity name. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getEntityName() |
||
44 | |||
45 | /** |
||
46 | * Configure filters |
||
47 | */ |
||
48 | public function buildFilters() |
||
52 | |||
53 | /** |
||
54 | * Configure the visible columns |
||
55 | */ |
||
56 | public function buildFields() |
||
60 | |||
61 | /** |
||
62 | * @param QueryBuilder $queryBuilder |
||
63 | */ |
||
64 | public function adaptQueryBuilder(QueryBuilder $queryBuilder) |
||
68 | |||
69 | /** |
||
70 | * Overwrite the parent function. By adding the TranslationWalker, we can order by the translated fields. |
||
71 | * |
||
72 | * @return \Doctrine\ORM\Query|null |
||
73 | */ |
||
74 | public function getQuery() |
||
88 | } |
||
89 |
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.