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 |
||
| 13 | View Code Duplication | class ToFloat implements UnaryFunction |
|
| 14 | { |
||
| 15 | /** @var float */ |
||
| 16 | private $default; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param float $default |
||
| 20 | */ |
||
| 21 | 27 | public function __construct($default = 0.0) |
|
| 25 | |||
| 26 | /** |
||
| 27 | * @param mixed $input |
||
| 28 | * |
||
| 29 | * @return float |
||
| 30 | */ |
||
| 31 | 27 | public function __invoke($input) |
|
| 43 | } |
||
| 44 |