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 |
||
19 | abstract class AbstractArticlePageAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $locale; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $permission; |
||
30 | |||
31 | /** |
||
32 | * @param EntityManager $em The entity manager |
||
33 | * @param AclHelper $aclHelper The ACL helper |
||
34 | * @param string $locale The current locale |
||
35 | * @param string $permission The permission |
||
36 | */ |
||
37 | View Code Duplication | public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission) |
|
45 | |||
46 | /** |
||
47 | * Return current bundle name. |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getBundleName() |
||
55 | |||
56 | /** |
||
57 | * Return current entity name. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getEntityName() |
||
65 | |||
66 | /** |
||
67 | * Configure filters |
||
68 | */ |
||
69 | View Code Duplication | public function buildFilters() |
|
76 | |||
77 | /** |
||
78 | * Configure the visible columns |
||
79 | */ |
||
80 | View Code Duplication | public function buildFields() |
|
87 | |||
88 | /** |
||
89 | * @return QueryBuilder |
||
90 | */ |
||
91 | protected function getQueryBuilder() |
||
99 | |||
100 | /** |
||
101 | * @param QueryBuilder $queryBuilder The query builder |
||
102 | */ |
||
103 | public function adaptQueryBuilder(QueryBuilder $queryBuilder) |
||
115 | |||
116 | /** |
||
117 | * @param mixed $item |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | View Code Duplication | public function getEditUrlFor($item) |
|
131 | |||
132 | /** |
||
133 | * Get the delete url for the given $item |
||
134 | * |
||
135 | * @param object $item |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getDeleteUrlFor($item) |
||
149 | |||
150 | /** |
||
151 | * Returns the OverviewPage of these articles |
||
152 | * |
||
153 | * @return AbstractArticleOverviewPage |
||
154 | */ |
||
155 | public function getOverviewPage() |
||
166 | |||
167 | /** |
||
168 | * Returns all overview pages |
||
169 | * |
||
170 | * @return mixed |
||
171 | */ |
||
172 | public function getOverviewPages() |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getListTemplate() |
||
184 | |||
185 | /** |
||
186 | * Returns the full entity class name |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getEntityClassName() |
||
194 | |||
195 | /** |
||
196 | * @return \Doctrine\ORM\EntityRepository |
||
197 | */ |
||
198 | abstract public function getOverviewPageRepository(); |
||
199 | } |
||
200 |
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.