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 | class Google extends SEOstats |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Gets the Google Pagerank |
||
| 23 | * |
||
| 24 | * @param string $url String, containing the query URL. |
||
| 25 | * @return integer Returns the Google PageRank. |
||
| 26 | */ |
||
| 27 | 2 | public static function getPageRank($url = false) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * Returns the total amount of results for a Google 'site:'-search for the object URL. |
||
| 43 | * |
||
| 44 | * @param string $url String, containing the query URL. |
||
| 45 | * @return integer Returns the total site-search result count. |
||
| 46 | */ |
||
| 47 | 1 | View Code Duplication | public static function getSiteindexTotal($url = false) |
| 54 | |||
| 55 | /** |
||
| 56 | * Returns the total amount of results for a Google 'link:'-search for the object URL. |
||
| 57 | * |
||
| 58 | * @param string $url String, containing the query URL. |
||
| 59 | * @return integer Returns the total link-search result count. |
||
| 60 | */ |
||
| 61 | 1 | View Code Duplication | public static function getBacklinksTotal($url = false) |
| 68 | |||
| 69 | /** |
||
| 70 | * Returns total amount of results for any Google search, |
||
| 71 | * requesting the deprecated Websearch API. |
||
| 72 | * |
||
| 73 | * @param string $url String, containing the query URL. |
||
| 74 | * @return integer Returns the total search result count. |
||
| 75 | */ |
||
| 76 | 3 | public static function getSearchResultsTotal($url = false) |
|
| 88 | |||
| 89 | 4 | public static function getPagespeedAnalysis($url = false, $strategy = 'desktop') |
|
| 104 | |||
| 105 | 2 | public static function getPagespeedScore($url = false, $strategy = 'desktop') |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Returns array, containing detailed results for any Google search. |
||
| 121 | * |
||
| 122 | * @param string $query String, containing the search query. |
||
| 123 | * @param string $tld String, containing the desired Google top level domain. |
||
| 124 | * @return array Returns array, containing the keys 'URL', 'Title' and 'Description'. |
||
| 125 | */ |
||
| 126 | public static function getSerps($query, $maxResults = 100, $domain = false) |
||
| 130 | } |
||
| 131 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.