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; |
||
20 | |||
21 | /** |
||
22 | * @var QueryBuilder |
||
23 | */ |
||
24 | protected $queryBuilder; |
||
25 | |||
26 | /** |
||
27 | * @var Pagerfanta |
||
28 | */ |
||
29 | private $pagerfanta; |
||
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 | 6 | 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 | 1 | 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 | 1 | View Code Duplication | public function getDeleteUrlFor($item) |
84 | |||
85 | /** |
||
86 | * @return Pagerfanta |
||
87 | */ |
||
88 | 1 | View Code Duplication | public function getPagerfanta() |
103 | |||
104 | /** |
||
105 | * @param array $params |
||
106 | */ |
||
107 | 2 | public function adaptQueryBuilder( |
|
108 | QueryBuilder $queryBuilder, |
||
109 | array $params = array() |
||
110 | ) { |
||
111 | 2 | $queryBuilder->where('1=1'); |
|
112 | 2 | } |
|
113 | |||
114 | /** |
||
115 | * @return int |
||
116 | */ |
||
117 | public function getCount() |
||
121 | |||
122 | /** |
||
123 | * @return array|mixed|\Traversable |
||
124 | */ |
||
125 | public function getItems() |
||
129 | |||
130 | /** |
||
131 | * Return an iterable statement or int for all items that matches the current filtering |
||
132 | * |
||
133 | * @return \Traversable|int |
||
134 | */ |
||
135 | 1 | public function getIterator() |
|
139 | |||
140 | /** |
||
141 | * @return QueryBuilder|null |
||
142 | */ |
||
143 | 2 | public function getQueryBuilder() |
|
167 | |||
168 | /** |
||
169 | * Set count field (must include table alias!) |
||
170 | * |
||
171 | * @param string $countField |
||
172 | * |
||
173 | * @return AbstractDoctrineDBALAdminListConfigurator |
||
174 | */ |
||
175 | 1 | public function setCountField($countField) |
|
181 | |||
182 | /** |
||
183 | * Get current count field (including table alias) |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | 2 | public function getCountField() |
|
191 | |||
192 | /** |
||
193 | * When doing the count you can turn the distinct on or off. |
||
194 | * |
||
195 | * @param bool $value |
||
196 | * |
||
197 | * @return AbstractDoctrineDBALAdminListConfigurator |
||
198 | */ |
||
199 | 1 | public function setUseDistinctCount($value) |
|
205 | |||
206 | /** |
||
207 | * Get current doDistinctCount |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | 2 | public function getUseDistinctCount() |
|
215 | } |
||
216 |
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.