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 |
||
20 | abstract class AbstractDoctrineORMAdminListConfigurator extends AbstractAdminListConfigurator |
||
21 | { |
||
22 | /** |
||
23 | * @var EntityManagerInterface |
||
24 | */ |
||
25 | protected $em; |
||
26 | |||
27 | /** |
||
28 | * @var Query |
||
29 | */ |
||
30 | private $query = null; |
||
31 | |||
32 | /** |
||
33 | * @var Pagerfanta |
||
34 | */ |
||
35 | private $pagerfanta = null; |
||
36 | |||
37 | /** |
||
38 | * @var PermissionDefinition |
||
39 | */ |
||
40 | private $permissionDef = null; |
||
41 | |||
42 | /** |
||
43 | * @var AclHelper |
||
44 | */ |
||
45 | protected $aclHelper = null; |
||
46 | |||
47 | /** |
||
48 | * AbstractDoctrineORMAdminListConfigurator constructor. |
||
49 | * |
||
50 | * @param EntityManagerInterface $em |
||
51 | * @param AclHelper|null $aclHelper |
||
52 | */ |
||
53 | public function __construct(EntityManagerInterface $em, AclHelper $aclHelper = null) |
||
58 | |||
59 | /** |
||
60 | * Return the url to edit the given $item |
||
61 | * |
||
62 | * @param object $item |
||
63 | * |
||
64 | * @return array |
||
|
|||
65 | */ |
||
66 | View Code Duplication | public function getEditUrlFor($item) |
|
76 | |||
77 | /** |
||
78 | * Get the delete url for the given $item |
||
79 | * |
||
80 | * @param object $item |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | View Code Duplication | public function getDeleteUrlFor($item) |
|
94 | |||
95 | /** |
||
96 | * @return Pagerfanta |
||
97 | */ |
||
98 | View Code Duplication | public function getPagerfanta() |
|
110 | |||
111 | /** |
||
112 | * @param QueryBuilder $queryBuilder |
||
113 | */ |
||
114 | public function adaptQueryBuilder(QueryBuilder $queryBuilder) |
||
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | public function getCount() |
||
126 | |||
127 | /** |
||
128 | * @return array|Traversable |
||
129 | */ |
||
130 | public function getItems() |
||
134 | |||
135 | /** |
||
136 | * Return an iterator for all items that matches the current filtering |
||
137 | * |
||
138 | * @return \Iterator |
||
139 | */ |
||
140 | public function getIterator() |
||
144 | |||
145 | /** |
||
146 | * @return Query|null |
||
147 | */ |
||
148 | public function getQuery() |
||
189 | |||
190 | /** |
||
191 | * @param QueryBuilder $queryBuilder |
||
192 | */ |
||
193 | protected function finishQueryBuilder(QueryBuilder $queryBuilder) |
||
199 | |||
200 | /** |
||
201 | * @return QueryBuilder |
||
202 | */ |
||
203 | protected function getQueryBuilder() |
||
211 | |||
212 | /** |
||
213 | * Get current permission definition. |
||
214 | * |
||
215 | * @return PermissionDefinition|null |
||
216 | */ |
||
217 | public function getPermissionDefinition() |
||
221 | |||
222 | /** |
||
223 | * Set permission definition. |
||
224 | * |
||
225 | * @param PermissionDefinition $permissionDef |
||
226 | * |
||
227 | * @return AbstractDoctrineORMAdminListConfigurator |
||
228 | */ |
||
229 | public function setPermissionDefinition(PermissionDefinition $permissionDef) |
||
235 | |||
236 | /** |
||
237 | * @param EntityManagerInterface $em |
||
238 | * |
||
239 | * @return AbstractDoctrineORMAdminListConfigurator |
||
240 | */ |
||
241 | public function setEntityManager(EntityManagerInterface $em) |
||
247 | |||
248 | /** |
||
249 | * @return EntityManagerInterface |
||
250 | */ |
||
251 | public function getEntityManager() |
||
255 | } |
||
256 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.