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\Task; |
||
| 24 | class Tracker { |
||
| 25 | |||
| 26 | use ConfigurationTrait; |
||
| 27 | use LoggerTrait; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | private $queued = []; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | private $running = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | private $completed = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Tracker constructor |
||
| 46 | * |
||
| 47 | * @param string $name |
||
|
|
|||
| 48 | * @param Configuration $configuration |
||
| 49 | * @param LoggerInterface $logger |
||
| 50 | */ |
||
| 51 | public function __construct(Configuration $configuration, LoggerInterface $logger) { |
||
| 57 | |||
| 58 | public function getQueued() { |
||
| 63 | |||
| 64 | public function setQueued(Request $request) { |
||
| 75 | |||
| 76 | public function countQueued() { |
||
| 81 | |||
| 82 | public function getRunning() { |
||
| 87 | |||
| 88 | public function setRunning($uid, $pid) { |
||
| 104 | |||
| 105 | public function countRunning() { |
||
| 110 | |||
| 111 | public function getCompleted() { |
||
| 116 | |||
| 117 | public function countCompleted() { |
||
| 122 | |||
| 123 | View Code Duplication | public function setCompleted($uid, Result $result) { |
|
| 136 | |||
| 137 | View Code Duplication | public function setAborted($uid, Result $result) { |
|
| 150 | |||
| 151 | public function getSucceeded() { |
||
| 158 | |||
| 159 | public function countSucceeded() { |
||
| 164 | |||
| 165 | public function getFailed() { |
||
| 172 | |||
| 173 | public function countFailed() { |
||
| 178 | |||
| 179 | public static function create(Configuration $configuration, LoggerInterface $logger) { |
||
| 184 | |||
| 185 | } |
||
| 186 |
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.