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 |
||
12 | class MediaObjectCreated implements SerializableInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var UUID |
||
16 | */ |
||
17 | protected $mediaObjectId; |
||
18 | |||
19 | /** |
||
20 | * @var MIMEType |
||
21 | */ |
||
22 | protected $mimeType; |
||
23 | |||
24 | /** |
||
25 | * @var String |
||
26 | */ |
||
27 | protected $description; |
||
28 | |||
29 | /** |
||
30 | * @var String |
||
31 | */ |
||
32 | protected $copyrightHolder; |
||
33 | |||
34 | /** |
||
35 | * @var Url |
||
36 | */ |
||
37 | protected $sourceLocation; |
||
38 | |||
39 | /** |
||
40 | * @var Language |
||
41 | */ |
||
42 | protected $language; |
||
43 | |||
44 | /** |
||
45 | * MediaObjectCreated constructor. |
||
46 | * @param UUID $id |
||
47 | * @param MIMEType $fileType |
||
48 | * @param \ValueObjects\StringLiteral\StringLiteral $description |
||
49 | * @param \ValueObjects\StringLiteral\StringLiteral $copyrightHolder |
||
50 | * @param Language $language |
||
51 | * @param Url $sourceLocation |
||
52 | */ |
||
53 | View Code Duplication | public function __construct( |
|
68 | |||
69 | /** |
||
70 | * @return Language |
||
71 | */ |
||
72 | public function getLanguage() |
||
76 | |||
77 | /** |
||
78 | * @return UUID |
||
79 | */ |
||
80 | public function getMediaObjectId() |
||
84 | |||
85 | /** |
||
86 | * @return StringLiteral |
||
87 | */ |
||
88 | public function getDescription() |
||
92 | |||
93 | /** |
||
94 | * @return StringLiteral |
||
95 | */ |
||
96 | public function getCopyrightHolder() |
||
100 | |||
101 | /** |
||
102 | * @return MIMEType |
||
103 | */ |
||
104 | public function getMimeType() |
||
108 | |||
109 | /** |
||
110 | * @return Url |
||
111 | */ |
||
112 | public function getSourceLocation() |
||
116 | |||
117 | /** |
||
118 | * @return array |
||
119 | */ |
||
120 | public function serialize() |
||
131 | |||
132 | /** |
||
133 | * @param array $data |
||
134 | * |
||
135 | * @return MediaObjectCreated The object instance |
||
136 | */ |
||
137 | View Code Duplication | public static function deserialize(array $data) |
|
148 | } |
||
149 |
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.