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 ToInteger implements UnaryFunction |
|
14 | { |
||
15 | /** @var int */ |
||
16 | private $default; |
||
17 | |||
18 | /** |
||
19 | * ToInteger constructor. |
||
20 | * |
||
21 | * @param int $default |
||
22 | */ |
||
23 | 29 | public function __construct($default = 0) |
|
27 | |||
28 | /** |
||
29 | * @param mixed $input |
||
30 | * |
||
31 | * @return int |
||
32 | */ |
||
33 | 31 | public function __invoke($input) |
|
45 | } |
||
46 |