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 |
||
| 13 | class HttpHelper |
||
| 14 | { |
||
| 15 | private $curlHandle; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * HttpHelper constructor. |
||
| 19 | * |
||
| 20 | * @param string $userAgent |
||
| 21 | * @param boolean $disableVerifyPeer |
||
| 22 | * @param string $cookieJar |
||
|
|
|||
| 23 | */ |
||
| 24 | public function __construct($userAgent, $disableVerifyPeer, $cookieJar = null) |
||
| 41 | |||
| 42 | public function __destruct() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Fetches the content of a URL, with an optional parameter set. |
||
| 49 | * |
||
| 50 | * @param string $url The URL to fetch. |
||
| 51 | * @param null|array $parameters Key/value pair of GET parameters to add to the request. |
||
| 52 | * Null lets you handle it yourself. |
||
| 53 | * |
||
| 54 | * @param array $headers |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | * @throws CurlException |
||
| 58 | */ |
||
| 59 | public function get($url, $parameters = null, $headers = array()) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Posts data to a URL |
||
| 85 | * |
||
| 86 | * @param string $url The URL to fetch. |
||
| 87 | * @param array $parameters Key/value pair of POST parameters to add to the request. |
||
| 88 | * @param array $headers |
||
| 89 | * |
||
| 90 | * @return string |
||
| 91 | * @throws CurlException |
||
| 92 | */ |
||
| 93 | public function post($url, $parameters, $headers = array()) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getError() |
||
| 120 | } |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.