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 |
||
| 7 | trait VectorLikeTrait |
||
| 8 | { |
||
| 9 | use ConstVectorLikeTrait, |
||
| 10 | CommonMutableContainerTrait; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * identical to at, implemented for ArrayAccess |
||
| 14 | */ |
||
| 15 | public function offsetGet($offset) |
||
| 19 | |||
| 20 | public function offsetSet($offset, $value) |
||
| 28 | |||
| 29 | public function offsetUnset($offset) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Stores a value into the Vector with the specified key, overwriting the |
||
| 36 | * previous value associated with the key. If the key is not present, |
||
| 37 | * an exception is thrown. "$vec->set($k,$v)" is semantically equivalent |
||
| 38 | * to "$vec[$k] = $v" (except that set() returns the Vector). |
||
| 39 | * |
||
| 40 | * @param $key |
||
| 41 | * @param $value |
||
| 42 | * @return $this |
||
| 43 | */ |
||
| 44 | public function set($key, $value) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function setAll($items) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public function add($item) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | public function removeKey($key) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | public function splice($offset, $length = null) |
||
| 112 | } |
||
| 113 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.