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 |
||
| 28 | class Dispatcher extends \PEIP\ABS\Dispatcher\Dispatcher implements |
||
| 29 | \PEIP\INF\Dispatcher\Dispatcher, |
||
| 30 | \PEIP\INF\Base\Plugable |
||
| 31 | { |
||
| 32 | protected $listeners = []; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Connects a listener. |
||
| 36 | * |
||
| 37 | * @param callable|PEIP\INF\Handler\Handler $listener |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | public function connect($listener) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Disconnects a listener. |
||
| 49 | * |
||
| 50 | * @param callable|PEIP\INF\Handler\Handler $listener |
||
| 51 | * |
||
| 52 | * @return void |
||
| 53 | */ |
||
| 54 | public function disconnect($listener) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Disconnects all listeners. |
||
| 66 | * |
||
| 67 | * @param callable|PEIP\INF\Handler\Handler $listener |
||
|
|
|||
| 68 | * |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | public function disconnectAll() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * returns wether any listeners are registered. |
||
| 78 | * |
||
| 79 | * @return bool wether any listeners are registered |
||
| 80 | */ |
||
| 81 | public function hasListeners() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * notifies all listeners on a subject. |
||
| 88 | * |
||
| 89 | * @param mixed $subject the subject |
||
| 90 | * |
||
| 91 | * @return void |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function notify($subject) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * notifies all listeners on a subject until one returns a boolean true value. |
||
| 105 | * |
||
| 106 | * @param mixed $subject the subject |
||
| 107 | * |
||
| 108 | * @return \PEIP\INF\Handler\Handler the listener which returned a boolean true value |
||
| 109 | */ |
||
| 110 | public function notifyUntil($subject) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * returns all listeners. |
||
| 121 | * |
||
| 122 | * @return array the listeners |
||
| 123 | */ |
||
| 124 | public function getListeners() |
||
| 128 | } |
||
| 129 |
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.