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 Comodojo\Extender\Tasks; |
||
| 30 | abstract class Task { |
||
| 31 | |||
| 32 | use TimestampTrait; |
||
| 33 | |||
| 34 | public $parameters; |
||
| 35 | |||
| 36 | public $name; |
||
| 37 | |||
| 38 | public $jobid; |
||
| 39 | |||
| 40 | public $pid; |
||
| 41 | |||
| 42 | protected $configuration; |
||
| 43 | |||
| 44 | protected $logger; |
||
| 45 | |||
| 46 | private $worklog; |
||
| 47 | |||
| 48 | private $worklog_id; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Task constructor. |
||
| 52 | * |
||
| 53 | * @param array $parameters Array of parameters (if any) |
||
| 54 | * @param \Monolog\Logger $logger |
||
| 55 | * @param int $pid Task PID (if any) |
||
|
|
|||
| 56 | * @param string $name Task Name |
||
| 57 | * @param int $timestamp Start timestamp (if null will be retrieved directly) |
||
| 58 | * @param bool $multithread Multithread switch |
||
| 59 | * |
||
| 60 | * @return Object $this |
||
| 61 | */ |
||
| 62 | final public function __construct( |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The run method; SHOULD be implemented by each task |
||
| 97 | */ |
||
| 98 | abstract public function run(); |
||
| 99 | |||
| 100 | |||
| 101 | /** |
||
| 102 | * Start task! |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | final public function start() { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Execute task. |
||
| 122 | * |
||
| 123 | * This method provides to: |
||
| 124 | * - setup worklog |
||
| 125 | * - invoke method "run", that should be defined in task implementation |
||
| 126 | */ |
||
| 127 | View Code Duplication | private function execTask() { |
|
| 165 | |||
| 166 | } |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.