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 |
||
14 | class StreamInfTag extends AbstractTag |
||
15 | { |
||
16 | use AttributesValueTagTrait; |
||
17 | |||
18 | const TAG_IDENTIFIER = '#EXT-X-STREAM-INF'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $programId; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $bandwidth; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $resolution; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $codecs; |
||
39 | |||
40 | /** |
||
41 | * @param string |
||
42 | * |
||
43 | * @return self |
||
44 | */ |
||
45 | 1 | public function setProgramId($programId) |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function getProgramId() |
|
59 | |||
60 | /** |
||
61 | * @param string |
||
62 | * |
||
63 | * @return self |
||
64 | */ |
||
65 | 1 | public function setBandwidth($bandwidth) |
|
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | 1 | public function getBandwidth() |
|
79 | |||
80 | /** |
||
81 | * @param string |
||
82 | * |
||
83 | * @return self |
||
84 | */ |
||
85 | 1 | public function setResolution($resolution) |
|
91 | |||
92 | /** |
||
93 | * @return string |
||
94 | */ |
||
95 | 1 | public function getResolution() |
|
99 | |||
100 | /** |
||
101 | * @param string |
||
102 | * |
||
103 | * @return self |
||
104 | */ |
||
105 | 1 | public function setCodecs($codecs) |
|
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | 1 | public function getCodecs() |
|
119 | |||
120 | 1 | View Code Duplication | public function dump() |
149 | |||
150 | 1 | protected function read($line) |
|
171 | } |
||
172 |
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.