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 |
||
30 | class AframeComponentInstaller extends LibraryInstaller |
||
31 | { |
||
32 | |||
33 | const AFRAME_PHP_VERSION = '0.3.0.1'; |
||
34 | |||
35 | const SUPPORTED_TYPES = array( |
||
36 | 'component', |
||
37 | 'aframe', |
||
38 | 'aframe-component' |
||
39 | ); |
||
40 | |||
41 | /** |
||
42 | * A-Frame Component vendor |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $aframe_component_vendor; |
||
47 | |||
48 | /** |
||
49 | * A-Frame Component package name |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $aframe_component_name; |
||
54 | |||
55 | /** |
||
56 | * Path to directory of A-Frame assets |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $public_root; |
||
61 | |||
62 | /** |
||
63 | * Path to A-Frame core scripts |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $public_core_dir; |
||
68 | |||
69 | /** |
||
70 | * URI of A-Frame assets relative to your document root |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $aframe_assets_url = '/aframe'; |
||
75 | |||
76 | /** |
||
77 | * Decides if the installer supports the given type |
||
78 | * and package. |
||
79 | * We only handle components with name prefix aframe |
||
80 | * |
||
81 | * @param string $packageType |
||
|
|||
82 | * @return bool |
||
83 | */ |
||
84 | public function supports($package_type) |
||
88 | |||
89 | /** |
||
90 | * Checks that provided package is installed. |
||
91 | * |
||
92 | * @param InstalledRepositoryInterface $repo |
||
93 | * repository in which to check |
||
94 | * @param PackageInterface $package |
||
95 | * package instance |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) |
||
103 | |||
104 | /** |
||
105 | * Installs specific package. |
||
106 | * |
||
107 | * @param InstalledRepositoryInterface $repo |
||
108 | * repository in which to check |
||
109 | * @param PackageInterface $package |
||
110 | * package instance |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public function install(InstalledRepositoryInterface $repo, PackageInterface $package) |
||
134 | |||
135 | /** |
||
136 | * Updates specific package. |
||
137 | * |
||
138 | * @param InstalledRepositoryInterface $repo |
||
139 | * repository in which to check |
||
140 | * @param PackageInterface $initial |
||
141 | * already installed package version |
||
142 | * @param PackageInterface $target |
||
143 | * updated version |
||
144 | * |
||
145 | * @throws InvalidArgumentException if $initial package is not installed |
||
146 | * @return void |
||
147 | */ |
||
148 | public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) |
||
168 | |||
169 | /** |
||
170 | * Remove the code |
||
171 | * |
||
172 | * @param PackageInterface $package |
||
173 | * @return void |
||
174 | */ |
||
175 | public function removeCode(PackageInterface $package) |
||
192 | |||
193 | /** |
||
194 | * Supoorted By Name |
||
195 | * |
||
196 | * Is package supoorted by name. All supported package names shoudl start with aframe |
||
197 | * |
||
198 | * @param string $pretty_name |
||
199 | * @return bool |
||
200 | */ |
||
201 | protected function supportedByName(string $pretty_name) |
||
208 | |||
209 | /** |
||
210 | * Get A-Frame component path |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getComponentPath() |
||
218 | |||
219 | /** |
||
220 | * Set A-Frame componet public path |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | protected function setComponentPath() |
||
228 | |||
229 | /** |
||
230 | * Get public path |
||
231 | * |
||
232 | * Path where all package dist files will be saved |
||
233 | * |
||
234 | * @return string $public_path |
||
235 | */ |
||
236 | public function getPublicRoot() |
||
241 | |||
242 | /** |
||
243 | * Get A-Frame assets path |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getPublicAframeCoreDir() |
||
251 | |||
252 | /** |
||
253 | * Get Composer Vendor dir |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | public function getVendorDir() |
||
261 | |||
262 | /** |
||
263 | * Get A-Frame core assets source path |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | public function getAframeCoreSrcDir() |
||
271 | |||
272 | /** |
||
273 | * Copy directory or files |
||
274 | * |
||
275 | * @param string $source |
||
276 | * @param string $dest |
||
277 | */ |
||
278 | public function copy(string $source, string $dest) |
||
298 | |||
299 | /** |
||
300 | * Remove files or directories |
||
301 | * |
||
302 | * @param string $pathname |
||
303 | * @return boolean |
||
304 | */ |
||
305 | public function rm(string $pathname) |
||
325 | |||
326 | /** |
||
327 | * initializeVendorDir |
||
328 | * |
||
329 | * @return void |
||
330 | */ |
||
331 | protected function initializeVendorDir() |
||
341 | |||
342 | /** |
||
343 | * Set A-Frame assets relative base url |
||
344 | */ |
||
345 | public function updateConfig() |
||
359 | } |
||
360 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.