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 |
||
| 31 | class DownloaderComment extends AbstractCheck |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * Guess magento edition and version |
||
| 35 | * |
||
| 36 | * @return array|boolean |
||
| 37 | */ |
||
| 38 | public function getInfo() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Guess Magento year from downloader url |
||
| 52 | * |
||
| 53 | * @param Response $response |
||
| 54 | * |
||
| 55 | * @return string|boolean |
||
| 56 | */ |
||
| 57 | public function getMagentoYear(Response $response) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Guess Magento version from downloader body |
||
| 71 | * |
||
| 72 | * @param Response $response |
||
| 73 | * |
||
| 74 | * @return string|boolean |
||
| 75 | */ |
||
| 76 | public function getMagentoVersion(Response $response) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Guess Magento edition from copyright year and version |
||
| 88 | * |
||
| 89 | * @param string $year |
||
| 90 | * @param string $version |
||
| 91 | * |
||
| 92 | * @return string |
||
| 93 | */ |
||
| 94 | protected function getMagentoEditionByYearAndVersion($year, $version) |
||
| 98 | } |
||
| 99 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: