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 |
||
40 | View Code Duplication | class MylinksShrinktheweb implements MylinksThumbPlugin |
|
|
|||
41 | { |
||
42 | private $image_width = 0; |
||
43 | private $site_url = null; |
||
44 | private $key = null; |
||
45 | private $attribution = "<a href=\"http://www.shrinktheweb.com\" target=\"_blank\" title=\"Thumbnail Screenshots by ShrinkTheWeb\">Thumbnail Screenshots by ShrinkTheWeb</a>"; |
||
46 | private $provider_url = 'http://images.shrinktheweb.com/xino.php'; |
||
47 | private $provider_name = 'ShrinkTheWeb'; |
||
48 | |||
49 | /** |
||
50 | * MylinksShrinktheweb constructor. |
||
51 | */ |
||
52 | public function __construct() |
||
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getProviderUrl() |
||
73 | |||
74 | /** |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getProviderName() |
||
81 | |||
82 | /** |
||
83 | * @param $sz |
||
84 | * @return mixed|void |
||
85 | */ |
||
86 | public function setShotSize($sz) |
||
96 | |||
97 | /** |
||
98 | * @return array |
||
99 | */ |
||
100 | public function getShotSize() |
||
104 | |||
105 | /** |
||
106 | * @param $url |
||
107 | * @return mixed|void |
||
108 | */ |
||
109 | public function setSiteUrl($url) |
||
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getSiteUrl() |
||
122 | |||
123 | /** |
||
124 | * @param null $attr |
||
125 | */ |
||
126 | public function setAttribution($attr = null) |
||
130 | |||
131 | /** |
||
132 | * @param int $allowhtml |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getAttribution($allowhtml = 0) |
||
145 | |||
146 | /** |
||
147 | * @param $key |
||
148 | * @return mixed|void |
||
149 | */ |
||
150 | public function setProviderPublicKey($key) |
||
154 | |||
155 | /** |
||
156 | * @return null |
||
157 | */ |
||
158 | public function getProviderPublicKey() |
||
162 | |||
163 | /** |
||
164 | * @param $key |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function setProviderPrivateKey($key) |
||
171 | |||
172 | /** |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function getProviderPrivateKey() |
||
179 | } |
||
180 |
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.