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 |
||
19 | abstract class ShaStrategyAbstract implements StrategyInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $versionUrl; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $pharUrl; |
||
31 | |||
32 | /** |
||
33 | * Download the remote Phar file. |
||
34 | * |
||
35 | * @param Updater $updater |
||
36 | * @return void |
||
37 | */ |
||
38 | View Code Duplication | public function download(Updater $updater) |
|
52 | |||
53 | /** |
||
54 | * Retrieve the current version available remotely. |
||
55 | * |
||
56 | * @param Updater $updater |
||
57 | * @return string|bool |
||
58 | */ |
||
59 | public function getCurrentRemoteVersion(Updater $updater) |
||
83 | |||
84 | /** |
||
85 | * Retrieve the current version of the local phar file. |
||
86 | * |
||
87 | * @param Updater $updater |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getCurrentLocalVersion(Updater $updater) |
||
94 | |||
95 | /** |
||
96 | * Set URL to phar file |
||
97 | * |
||
98 | * @param string $url |
||
99 | */ |
||
100 | public function setPharUrl($url) |
||
109 | |||
110 | /** |
||
111 | * Get URL for phar file |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getPharUrl() |
||
119 | |||
120 | /** |
||
121 | * Set URL to version file |
||
122 | * |
||
123 | * @param string $url |
||
124 | */ |
||
125 | public function setVersionUrl($url) |
||
134 | |||
135 | /** |
||
136 | * Get URL for version file |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getVersionUrl() |
||
144 | |||
145 | protected function validateAllowedUrl($url) |
||
153 | } |
||
154 |
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.