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 | abstract class AbstractDoctrineDBALAdminListConfigurator extends AbstractAdminListConfigurator |
||
15 | { |
||
16 | /** |
||
17 | * @var Connection |
||
18 | */ |
||
19 | protected $connection = null; |
||
20 | |||
21 | /** |
||
22 | * @var QueryBuilder |
||
23 | */ |
||
24 | protected $queryBuilder = null; |
||
25 | |||
26 | /** |
||
27 | * @var Pagerfanta |
||
28 | */ |
||
29 | private $pagerfanta = null; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $countField = 'b.id'; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $useDistinctCount = true; |
||
40 | |||
41 | /** |
||
42 | * @param Connection $connection |
||
43 | */ |
||
44 | public function __construct(Connection $connection) |
||
48 | |||
49 | /** |
||
50 | * Return the url to edit the given $item |
||
51 | * |
||
52 | * @param array $item |
||
53 | * |
||
54 | * @return array |
||
|
|||
55 | */ |
||
56 | View Code Duplication | public function getEditUrlFor($item) |
|
66 | |||
67 | /** |
||
68 | * Get the delete url for the given $item |
||
69 | * |
||
70 | * @param array $item |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | View Code Duplication | public function getDeleteUrlFor($item) |
|
84 | |||
85 | /** |
||
86 | * @return Pagerfanta |
||
87 | */ |
||
88 | View Code Duplication | public function getPagerfanta() |
|
103 | |||
104 | /** |
||
105 | * @param array $params |
||
106 | */ |
||
107 | public function adaptQueryBuilder( |
||
114 | |||
115 | /** |
||
116 | * @return int |
||
117 | */ |
||
118 | public function getCount() |
||
122 | |||
123 | /** |
||
124 | * @return array|mixed|\Traversable |
||
125 | */ |
||
126 | public function getItems() |
||
130 | |||
131 | /** |
||
132 | * Return an iterable statement or int for all items that matches the current filtering |
||
133 | * |
||
134 | * @return \Traversable|int |
||
135 | */ |
||
136 | public function getIterator() |
||
142 | |||
143 | /** |
||
144 | * @return QueryBuilder|null |
||
145 | */ |
||
146 | public function getQueryBuilder() |
||
170 | |||
171 | /** |
||
172 | * Set count field (must include table alias!) |
||
173 | * |
||
174 | * @param string $countField |
||
175 | * |
||
176 | * @return AbstractDoctrineDBALAdminListConfigurator |
||
177 | */ |
||
178 | public function setCountField($countField) |
||
184 | |||
185 | /** |
||
186 | * Get current count field (including table alias) |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getCountField() |
||
194 | |||
195 | /** |
||
196 | * When doing the count you can turn the distinct on or off. |
||
197 | * |
||
198 | * @param bool $value |
||
199 | * |
||
200 | * @return AbstractDoctrineDBALAdminListConfigurator |
||
201 | */ |
||
202 | public function setUseDistinctCount($value) |
||
208 | |||
209 | /** |
||
210 | * Get current doDistinctCount |
||
211 | * |
||
212 | * @return bool |
||
213 | */ |
||
214 | public function getUseDistinctCount() |
||
218 | } |
||
219 |
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.