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') |
|
| 90 | { |
||
| 91 | 4 | if ('' == Config\ApiKeys::getGoogleSimpleApiAccessKey()) { |
|
| 92 | throw new E('In order to use the PageSpeed API, you must obtain |
||
| 93 | and set an API key first (see SEOstats\Config\ApiKeys.php).'); |
||
| 94 | exit(0); |
||
| 95 | } |
||
| 96 | |||
| 97 | 4 | $url = parent::getUrl($url); |
|
| 98 | 4 | $url = sprintf(Config\Services::GOOGLE_PAGESPEED_URL, |
|
| 99 | 4 | $url, $strategy, Config\ApiKeys::getGoogleSimpleApiAccessKey()); |
|
| 100 | |||
| 101 | 4 | $ret = static::_getPage($url); |
|
| 102 | |||
| 103 | 4 | return Helper\Json::decode($ret); |
|
| 104 | } |
||
| 105 | |||
| 106 | 2 | public static function getPagespeedScore($url = false, $strategy = 'desktop') |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Returns array, containing detailed results for any Google search. |
||
| 123 | * |
||
| 124 | * @param string $query String, containing the search query. |
||
| 125 | * @param string $tld String, containing the desired Google top level domain. |
||
| 126 | * @return array Returns array, containing the keys 'URL', 'Title' and 'Description'. |
||
| 127 | */ |
||
| 128 | public static function getSerps($query, $maxResults=100, $domain=false) |
||
| 132 | } |
||
| 133 |
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.