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 GetByIdResponse |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * @var \DateTime |
||
17 | */ |
||
18 | private $data; |
||
19 | |||
20 | /** |
||
21 | * @var Terminal |
||
22 | */ |
||
23 | private $terminal; |
||
24 | |||
25 | /** |
||
26 | * GetByIdResponse constructor. |
||
27 | */ |
||
28 | public function __construct() |
||
31 | |||
32 | /** |
||
33 | * @return \DateTime |
||
34 | */ |
||
35 | public function getData() |
||
39 | |||
40 | /** |
||
41 | * @param \DateTime $data |
||
42 | * @return GetByIdResponse |
||
43 | */ |
||
44 | public function setData($data) |
||
53 | |||
54 | /** |
||
55 | * @return Terminal |
||
56 | */ |
||
57 | public function getTerminal() |
||
61 | |||
62 | /** |
||
63 | * @param Terminal $terminal |
||
64 | * @return GetByIdResponse |
||
65 | */ |
||
66 | public function setTerminal($terminal) |
||
75 | |||
76 | } |
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.