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 | final 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 | View Code Duplication | public function __construct( |
|
59 | |||
60 | public function getLanguage(): Language |
||
64 | |||
65 | public function getMediaObjectId(): UUID |
||
69 | |||
70 | public function getDescription(): StringLiteral |
||
74 | |||
75 | public function getCopyrightHolder(): StringLiteral |
||
79 | |||
80 | public function getMimeType(): MIMEType |
||
84 | |||
85 | public function getSourceLocation(): Url |
||
89 | |||
90 | public function serialize(): array |
||
101 | |||
102 | View Code Duplication | public static function deserialize(array $data): MediaObjectCreated |
|
113 | } |
||
114 |
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.