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 |
||
11 | class LeadRepository extends EntityRepository |
||
12 | { |
||
13 | /** |
||
14 | * Returns top $limit opportunities grouped by lead source |
||
15 | * |
||
16 | * @deprecated since 1.10. Use OpportunityRepository::getOpportunitiesCountGroupByLeadSource instead |
||
17 | * @see OpportunityRepository::getOpportunitiesCountGroupByLeadSource |
||
18 | * |
||
19 | * @param AclHelper $aclHelper |
||
20 | * @param int $limit |
||
21 | * @param array $dateRange |
||
22 | * |
||
23 | * @return array [itemCount, label] |
||
24 | */ |
||
25 | public function getOpportunitiesByLeadSource(AclHelper $aclHelper, $limit = 10, $dateRange = null, $owners = []) |
||
46 | |||
47 | /** |
||
48 | * @deprecated since 1.10. Used by deprecated getOpportunitiesByLeadSource |
||
49 | * @see LeadRepository::getOpportunitiesByLeadSource |
||
50 | * |
||
51 | * @param array $rows |
||
52 | * @param int $limit |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | protected function processOpportunitiesByLeadSource(array $rows, $limit) |
||
99 | |||
100 | /** |
||
101 | * @deprecated since 1.10. Used by deprecated getOpportunitiesByLeadSource |
||
102 | * @see LeadRepository::getOpportunitiesByLeadSource |
||
103 | * |
||
104 | * @param array $rows |
||
105 | * |
||
106 | * @return int |
||
107 | */ |
||
108 | protected function sumCount(array $rows) |
||
117 | |||
118 | /** |
||
119 | * @deprecated since 1.10. Used by deprecated getOpportunitiesByLeadSource |
||
120 | * @see LeadRepository::getOpportunitiesByLeadSource |
||
121 | * |
||
122 | * @param array $rows |
||
123 | */ |
||
124 | protected function sortByCountReverse(array &$rows) |
||
137 | |||
138 | /** |
||
139 | * @param AclHelper $aclHelper |
||
140 | * @param \DateTime $start |
||
141 | * @param \DateTime $end |
||
142 | * @param int[] $owners |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | public function getLeadsCount(AclHelper $aclHelper, \DateTime $start = null, \DateTime $end = null, $owners = []) |
||
154 | |||
155 | /** |
||
156 | * @param AclHelper $aclHelper |
||
157 | * @param \DateTime $start |
||
158 | * @param \DateTime $end |
||
159 | * @param int[] $owners |
||
160 | * |
||
161 | * @return int |
||
162 | */ |
||
163 | public function getNewLeadsCount(AclHelper $aclHelper, \DateTime $start = null, \DateTime $end = null, $owners = []) |
||
169 | |||
170 | /** |
||
171 | * @param AclHelper $aclHelper |
||
172 | * @param int[] $owners |
||
173 | * |
||
174 | * @return int |
||
175 | */ |
||
176 | public function getOpenLeadsCount(AclHelper $aclHelper, $owners = []) |
||
185 | |||
186 | /** |
||
187 | * @param \DateTime $start |
||
188 | * @param \DateTime $end |
||
189 | * @param int[] $owners |
||
190 | * |
||
191 | * @return QueryBuilder |
||
192 | */ |
||
193 | View Code Duplication | protected function createLeadsCountQb( |
|
219 | } |
||
220 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.