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 |
||
| 27 | class BindingDescriptorCollection |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var BindingDescriptor[][] |
||
| 31 | */ |
||
| 32 | private $map = array(); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Adds a binding descriptor. |
||
| 36 | * |
||
| 37 | * @param BindingDescriptor $bindingDescriptor The binding descriptor. |
||
| 38 | */ |
||
| 39 | 24 | public function add(BindingDescriptor $bindingDescriptor) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Removes a binding descriptor. |
||
| 50 | * |
||
| 51 | * This method ignores non-existing binding descriptors. |
||
| 52 | * |
||
| 53 | * @param Binding $binding The described binding. |
||
| 54 | * @param string $moduleName The name of the module containing the type. |
||
| 55 | */ |
||
| 56 | public function remove(Binding $binding, $moduleName) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Returns a binding descriptor. |
||
| 73 | * |
||
| 74 | * @param Uuid $uuid The UUID of the binding descriptor. |
||
|
|
|||
| 75 | * |
||
| 76 | * @return BindingDescriptor The binding descriptor. |
||
| 77 | * |
||
| 78 | * @throws OutOfBoundsException If no binding descriptor was set for the |
||
| 79 | * given UUID. |
||
| 80 | */ |
||
| 81 | 1 | public function get(Binding $binding, $moduleName) |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Returns whether a binding descriptor exists. |
||
| 100 | * |
||
| 101 | * @param Uuid $uuid The UUID of the binding descriptor. |
||
| 102 | * |
||
| 103 | * @return bool Returns `true` if a binding descriptor was set for the given |
||
| 104 | * UUID. |
||
| 105 | */ |
||
| 106 | 24 | public function contains(Binding $binding, $moduleName = null) |
|
| 132 | |||
| 133 | 6 | public function listByBinding(Binding $binding) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Returns the contents of the collection as array. |
||
| 150 | * |
||
| 151 | * @return BindingDescriptor[] An array containing all bindings indexed by UUID. |
||
| 152 | */ |
||
| 153 | 52 | public function toArray() |
|
| 157 | |||
| 158 | /** |
||
| 159 | * Returns whether the collection is empty. |
||
| 160 | * |
||
| 161 | * @return bool Returns `true` if the collection is empty and `false` |
||
| 162 | * otherwise. |
||
| 163 | */ |
||
| 164 | 2 | public function isEmpty() |
|
| 168 | } |
||
| 169 |
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.