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 |
||
24 | View Code Duplication | class SingleCallTransportEvent extends AbstractEvent |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * @var ActionInterface |
||
28 | */ |
||
29 | protected $action; |
||
30 | |||
31 | /** |
||
32 | * @var mixed |
||
33 | */ |
||
34 | protected $result; |
||
35 | |||
36 | /** |
||
37 | * @param RemoteAdapterInterface $remoteAdapter |
||
38 | * @param ActionInterface $action |
||
39 | * @param mixed $result |
||
40 | */ |
||
41 | public function __construct(RemoteAdapterInterface $remoteAdapter, ActionInterface $action, $result = null) |
||
47 | |||
48 | /** |
||
49 | * @param ActionInterface $action |
||
50 | */ |
||
51 | public function setAction(ActionInterface $action) |
||
55 | |||
56 | /** |
||
57 | * @return ActionInterface |
||
58 | */ |
||
59 | public function getAction() |
||
63 | |||
64 | /** |
||
65 | * @param $result |
||
66 | */ |
||
67 | public function setResult($result) |
||
71 | |||
72 | /** |
||
73 | * @return mixed |
||
74 | */ |
||
75 | public function getResult() |
||
79 | } |
||
80 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.