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 |
||
23 | final class RobotMover |
||
24 | { |
||
25 | private $repository; |
||
26 | |||
27 | private $logger; |
||
28 | |||
29 | /** |
||
30 | * @param RobotRepositoryInterface $repository |
||
31 | * @param LoggerInterface $logger |
||
32 | */ |
||
33 | 7 | public function __construct( |
|
40 | |||
41 | /** |
||
42 | * @Subscribe |
||
43 | * |
||
44 | * @param TurnLeft $command |
||
45 | */ |
||
46 | 1 | View Code Duplication | public function handleTurningLeft(TurnLeft $command): void |
56 | |||
57 | /** |
||
58 | * @Subscribe |
||
59 | * |
||
60 | * @param TurnRight $command |
||
61 | */ |
||
62 | 1 | public function handleTurningRight(TurnRight $command): void |
|
72 | |||
73 | /** |
||
74 | * @Subscribe |
||
75 | * |
||
76 | * @param MoveForward $command |
||
77 | */ |
||
78 | 1 | View Code Duplication | public function handleMoveForward(MoveForward $command): void |
88 | |||
89 | /** |
||
90 | * @return Robot |
||
91 | */ |
||
92 | 3 | private function getRobot(): Robot |
|
104 | } |
||
105 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.