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 |
||
8 | View Code Duplication | class VideoWebsiteCard extends Resource |
|
|
|||
9 | { |
||
10 | const RESOURCE_COLLECTION = 'accounts/{account_id}/cards/video_website'; |
||
11 | const RESOURCE = 'accounts/{account_id}/cards/video_website/{id}'; |
||
12 | |||
13 | /** Read Only */ |
||
14 | protected $id; |
||
15 | protected $preview_url; |
||
16 | protected $created_at; |
||
17 | protected $updated_at; |
||
18 | protected $deleted; |
||
19 | |||
20 | protected $properties = [ |
||
21 | VideoWebsiteCardFields::NAME, |
||
22 | VideoWebsiteCardFields::WEBSITE_TITLE, |
||
23 | VideoWebsiteCardFields::WEBSITE_URL, |
||
24 | VideoWebsiteCardFields::VIDEO_ID, |
||
25 | ]; |
||
26 | |||
27 | /** Writable */ |
||
28 | protected $name; |
||
29 | protected $website_title; |
||
30 | protected $website_url; |
||
31 | protected $video_id; |
||
32 | |||
33 | /** |
||
34 | * @return mixed |
||
35 | */ |
||
36 | public function getId() |
||
40 | |||
41 | /** |
||
42 | * @return array |
||
43 | */ |
||
44 | public function getProperties() |
||
48 | |||
49 | /** |
||
50 | * @param array $properties |
||
51 | */ |
||
52 | public function setProperties($properties) |
||
56 | |||
57 | /** |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function getName() |
||
64 | |||
65 | /** |
||
66 | * @param mixed $name |
||
67 | */ |
||
68 | public function setName($name) |
||
72 | |||
73 | /** |
||
74 | * @return mixed |
||
75 | */ |
||
76 | public function getWebsiteTitle() |
||
80 | |||
81 | /** |
||
82 | * @param mixed $website_title |
||
83 | */ |
||
84 | public function setWebsiteTitle($website_title) |
||
88 | |||
89 | /** |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function getWebsiteUrl() |
||
96 | |||
97 | /** |
||
98 | * @param mixed $website_url |
||
99 | */ |
||
100 | public function setWebsiteUrl($website_url) |
||
104 | |||
105 | /** |
||
106 | * @return mixed |
||
107 | */ |
||
108 | public function getVideoId() |
||
112 | |||
113 | /** |
||
114 | * @param mixed $video_id |
||
115 | */ |
||
116 | public function setVideoId($video_id) |
||
120 | |||
121 | /** |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function getPreviewUrl() |
||
128 | |||
129 | /** |
||
130 | * @return mixed |
||
131 | */ |
||
132 | public function getCreatedAt() |
||
136 | |||
137 | /** |
||
138 | * @return mixed |
||
139 | */ |
||
140 | public function getUpdatedAt() |
||
144 | |||
145 | /** |
||
146 | * @return mixed |
||
147 | */ |
||
148 | public function getDeleted() |
||
152 | } |
||
153 |
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.