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 |
||
| 19 | class ObjectIterator extends Collection |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var Converter |
||
| 23 | */ |
||
| 24 | private $converter; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array Aliases information. |
||
| 28 | */ |
||
| 29 | private $alias; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $rawObjects; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Using part of abstract iterator functionality only. |
||
| 38 | * |
||
| 39 | * @param Converter $converter |
||
| 40 | * @param array $objects |
||
| 41 | * @param array $alias |
||
| 42 | */ |
||
| 43 | public function __construct($converter, $objects, $alias) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | protected function convertDocument(array $document) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | View Code Duplication | public function current() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | View Code Duplication | public function offsetGet($offset) |
|
| 103 | } |
||
| 104 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.