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 namespace Maqe\Qwatcher; |
||
11 | class Qwatcher extends QwatchersAbstract |
||
12 | { |
||
13 | private $trackTransformer; |
||
14 | |||
15 | protected $statusable = []; |
||
16 | |||
17 | protected $queryable = ['sort', 'limit']; |
||
18 | |||
19 | protected $sortColumn = 'id'; |
||
20 | |||
21 | protected $sortOrder = 'asc'; |
||
22 | |||
23 | protected $sortable = ['id', 'driver', 'queue_at', 'job_name', 'process_at', 'success_at', 'failed_at']; |
||
24 | |||
25 | protected $limit = null; |
||
26 | |||
27 | public function __construct() |
||
32 | |||
33 | /** |
||
34 | * Insert or update Track table depend on TracksInterface sub class (Adapter) |
||
35 | * |
||
36 | * @param TracksInterface $tracks Sub class that implements TracksInterface |
||
37 | * @return mixed |
||
38 | */ |
||
39 | public static function tracks(TracksInterface $tracks) |
||
43 | |||
44 | /** |
||
45 | * Added sort order to $this->sortOrder string, use with builder |
||
46 | * |
||
47 | * @param string $sortBy The sort string |
||
|
|||
48 | * @return $this |
||
49 | */ |
||
50 | public function sortBy($sortColumn = 'id', $sortOrder = 'asc') |
||
58 | |||
59 | /** |
||
60 | * Set limit record to show |
||
61 | * |
||
62 | * @param integer $limit The number of record to retrieve |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function limit($limit) |
||
71 | |||
72 | /** |
||
73 | * Get the list of the queue track |
||
74 | * |
||
75 | * @return collection |
||
76 | */ |
||
77 | View Code Duplication | public function all() |
|
87 | |||
88 | /** |
||
89 | * Get paginate list of the queue track |
||
90 | * |
||
91 | * @param $perPage The number of per page |
||
92 | * @return collection |
||
93 | */ |
||
94 | View Code Duplication | public function paginate($perPage) |
|
104 | |||
105 | /** |
||
106 | * Get the track record by id |
||
107 | * |
||
108 | * @param $id The track id |
||
109 | * @return object |
||
110 | */ |
||
111 | public function getById($id) |
||
115 | |||
116 | /** |
||
117 | * Get the track record by current status |
||
118 | * |
||
119 | * @param $status The track status |
||
120 | * @param $perPage The number of per page |
||
121 | * @return collection |
||
122 | */ |
||
123 | public function getByStatus($status, $per_page = null) |
||
145 | |||
146 | /** |
||
147 | * Get the track record by job name |
||
148 | * |
||
149 | * @param $name The job name |
||
150 | * @param $perPage The number of per page |
||
151 | * @return collection |
||
152 | */ |
||
153 | public function getByJobName($name, $per_page = null) |
||
167 | |||
168 | /** |
||
169 | * Filter by queue date is not null (get queue that not run the job yet) |
||
170 | * - process, succeed and failed must be null |
||
171 | * |
||
172 | * @param Builder $builder The tracks builder |
||
173 | * @return Builder The query builder with filter applied. |
||
174 | */ |
||
175 | protected function filterByQueue(Builder $builder) |
||
182 | |||
183 | /** |
||
184 | * Filter by process date is not null |
||
185 | * - succeed and failed must be null |
||
186 | * |
||
187 | * @param Builder $builder The tracks builder |
||
188 | * @return Builder The query builder with filter applied. |
||
189 | */ |
||
190 | protected function filterByProcess(Builder $builder) |
||
197 | |||
198 | /** |
||
199 | * Filter by succeed date is not null |
||
200 | * - process is not null |
||
201 | * - failed is null |
||
202 | * |
||
203 | * @param Builder $builder The tracks builder |
||
204 | * @return Builder The query builder with filter applied. |
||
205 | */ |
||
206 | protected function filterBySucceed(Builder $builder) |
||
212 | |||
213 | /** |
||
214 | * Filter by failed date is not null |
||
215 | * - succeed is null |
||
216 | * |
||
217 | * @param Builder $builder The tracks builder |
||
218 | * @return Builder The query builder with filter applied. |
||
219 | */ |
||
220 | protected function filterByFailed(Builder $builder) |
||
226 | |||
227 | /** |
||
228 | * Filter sort order column string |
||
229 | * |
||
230 | * @param string $sortColumn The sort order column string |
||
231 | * @return stirng |
||
232 | */ |
||
233 | protected function filterSortColumn($sortColumn) |
||
237 | |||
238 | /** |
||
239 | * Filter sort order string, allowed only asc, desc |
||
240 | * |
||
241 | * @param string $sortOrder The sort order string |
||
242 | * @return stirng |
||
243 | */ |
||
244 | protected function filterSortOrder($sortOrder) |
||
248 | |||
249 | /** |
||
250 | * Apply limit if $this->limit is not null |
||
251 | * |
||
252 | * @param Builder $builder The tracks builder |
||
253 | * @return Builder The query builder with take applied. |
||
254 | */ |
||
255 | protected function applyLimit(Builder $builder) |
||
259 | |||
260 | protected function applySort(Builder $builder) |
||
264 | } |
||
265 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.