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 |
||
9 | class CUrl |
||
10 | { |
||
11 | use \Anax\TConfigure; |
||
12 | |||
13 | |||
14 | |||
15 | /** |
||
16 | * Properties |
||
17 | * |
||
18 | */ |
||
19 | const URL_CLEAN = 'clean'; // controller/action/param1/param2 |
||
20 | const URL_APPEND = 'append'; // index.php/controller/action/param1/param2 |
||
21 | |||
22 | private $urlType = self::URL_APPEND; // What type of urls to generate |
||
23 | |||
24 | private $siteUrl = null; // Siteurl to prepend to all absolute urls created |
||
25 | private $baseUrl = null; // Baseurl to prepend to all relative urls created |
||
26 | private $scriptName = null; // Name of the frontcontroller script |
||
27 | |||
28 | |||
29 | private $staticSiteUrl = null; // Siteurl to prepend to all absolute urls for assets |
||
30 | private $staticBaseUrl = null; // Baseurl to prepend to all relative urls for assets |
||
31 | |||
32 | |||
33 | |||
34 | /** |
||
35 | * Set default values from configuration. |
||
36 | * |
||
37 | * @return this. |
||
|
|||
38 | */ |
||
39 | 17 | public function setDefaultsFromConfiguration() |
|
60 | 4 | ||
61 | |||
62 | 4 | ||
63 | /** |
||
64 | * Create an url and prepending the baseUrl. |
||
65 | * |
||
66 | * @param string $uri part of uri to use when creating an url. |
||
67 | * "" or null means baseurl to current |
||
68 | * frontcontroller. |
||
69 | * @param string $baseuri optional base to prepend uri. |
||
70 | * |
||
71 | * @return string as resulting url. |
||
72 | */ |
||
73 | public function create($uri = null, $baseuri = null) |
||
117 | |||
118 | |||
119 | |||
120 | 2 | /** |
|
121 | * Create an url and prepend the baseUrl to the directory of |
||
122 | 2 | * the frontcontroller. |
|
123 | 2 | * |
|
124 | 2 | * @param string $uri part of uri to use when creating an url. |
|
125 | * "" or null means baseurl to directory of |
||
126 | * the current frontcontroller. |
||
127 | * |
||
128 | * @return string as resulting url. |
||
129 | */ |
||
130 | public function createRelative($uri = null) |
||
149 | |||
150 | |||
151 | 18 | ||
152 | /** |
||
153 | 18 | * Create an url for a static asset. |
|
154 | 18 | * |
|
155 | * @param string $uri part of uri to use when creating an url. |
||
156 | * |
||
157 | * @return string as resulting url. |
||
158 | */ |
||
159 | public function asset($uri = null) |
||
182 | |||
183 | 4 | ||
184 | 4 | ||
185 | /** |
||
186 | * Set the siteUrl to prepend all absolute urls created. |
||
187 | * |
||
188 | * @param string $url part of url to use when creating an url. |
||
189 | * |
||
190 | * @return $this |
||
191 | */ |
||
192 | public function setSiteUrl($url) |
||
197 | |||
198 | 7 | ||
199 | 7 | ||
200 | /** |
||
201 | * Set the baseUrl to prepend all relative urls created. |
||
202 | * |
||
203 | * @param string $url part of url to use when creating an url. |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function setBaseUrl($url) |
||
212 | |||
213 | 15 | ||
214 | 1 | ||
215 | /** |
||
216 | * Set the siteUrl to prepend absolute urls for assets. |
||
217 | 14 | * |
|
218 | 14 | * @param string $url part of url to use when creating an url. |
|
219 | * |
||
220 | * @return $this |
||
221 | */ |
||
222 | public function setStaticSiteUrl($url) |
||
227 | |||
228 | |||
229 | |||
230 | /** |
||
231 | * Set the baseUrl to prepend relative urls for assets. |
||
232 | * |
||
233 | * @param string $url part of url to use when creating an url. |
||
234 | * |
||
235 | * @return $this |
||
236 | */ |
||
237 | public function setStaticBaseUrl($url) |
||
242 | |||
243 | |||
244 | |||
245 | /** |
||
246 | * Set the scriptname to use when creating URL_APPEND urls. |
||
247 | * |
||
248 | * @param string $name as the scriptname, for example index.php. |
||
249 | * |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function setScriptName($name) |
||
257 | |||
258 | |||
259 | |||
260 | /** |
||
261 | * Set the type of urls to be generated, URL_CLEAN, URL_APPEND. |
||
262 | * |
||
263 | * @param string $type what type of urls to create. |
||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function setUrlType($type) |
||
276 | |||
277 | |||
278 | |||
279 | /** |
||
280 | * Create a slug of a string, to be used as url. |
||
281 | * |
||
282 | * @param string $str the string to format as slug. |
||
283 | * |
||
284 | * @return str the formatted slug. |
||
285 | */ |
||
286 | public function slugify($str) |
||
294 | } |
||
295 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.