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 |
||
9 | class TableMatch extends AbstractTableElement |
||
10 | { |
||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | public $startInOld; |
||
15 | /** |
||
16 | * @var int |
||
17 | */ |
||
18 | public $startInNew; |
||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | public $endInOld; |
||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | public $endInNew; |
||
27 | |||
28 | /** |
||
29 | * TableMatch constructor. |
||
30 | * |
||
31 | * @param int $startInOld |
||
32 | * @param int $startInNew |
||
33 | * @param int $endInOld |
||
34 | * @param int $endInNew |
||
35 | */ |
||
36 | View Code Duplication | public function __construct($startInOld, $startInNew, $endInOld, $endInNew) |
|
43 | |||
44 | /** |
||
45 | * @return int |
||
46 | */ |
||
47 | public function getStartInOld() |
||
51 | |||
52 | /** |
||
53 | * @return int |
||
54 | */ |
||
55 | public function getStartInNew() |
||
59 | |||
60 | /** |
||
61 | * @return int |
||
62 | */ |
||
63 | public function getEndInOld() |
||
67 | |||
68 | /** |
||
69 | * @return int |
||
70 | */ |
||
71 | public function getEndInNew() |
||
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.