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 |
||
| 4 | class SuperSakeChecker |
||
|
|
|||
| 5 | { |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Checks if the supersake file in webroot is protected with htaccess or web.config |
||
| 9 | */ |
||
| 10 | public function superSakeIsNotProtected() |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return bool|string |
||
| 25 | */ |
||
| 26 | View Code Duplication | protected function checkHtAccessProtection() |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return bool|string |
||
| 39 | */ |
||
| 40 | View Code Duplication | protected function checkWebConfigProtection() |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Check if the web server is IIS and version greater than the given version. |
||
| 53 | * @return boolean |
||
| 54 | */ |
||
| 55 | public function isIIS($fromVersion = 7) { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return bool |
||
| 64 | */ |
||
| 65 | public function isApache() { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Find the webserver software running on the PHP host. |
||
| 75 | * @return string|boolean Server software or boolean FALSE |
||
| 76 | */ |
||
| 77 | public function findWebserver() { |
||
| 89 | } |
||
| 90 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.