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 |
||
| 16 | class YahooWeatherAPI implements YahooWeatherAPIInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var Client Goutte client |
||
| 20 | */ |
||
| 21 | protected $client; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var array last response from API |
||
| 25 | */ |
||
| 26 | protected $lastResponse; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string last woeid explicitly called |
||
| 30 | */ |
||
| 31 | protected $woeid; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string last city name explicitly called |
||
| 35 | */ |
||
| 36 | protected $city; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string the last url called |
||
| 40 | */ |
||
| 41 | protected $yql; |
||
| 42 | |||
| 43 | public function __construct() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function callApiWoeid($woeid = null, $unit = 'c') |
|
| 65 | |||
| 66 | /** |
||
| 67 | * {@inheritdoc} |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function callApiCityName($city = null, $unit = 'c') |
|
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | public function callApi($yql = null) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get lastResponse. |
||
| 113 | * |
||
| 114 | * @param bool $toJson choose format for the return value (array or json) |
||
| 115 | * |
||
| 116 | * @return array|string |
||
| 117 | */ |
||
| 118 | public function getLastResponse($toJson = false) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Set lastResponse. |
||
| 125 | * |
||
| 126 | * @param array $data data from json_encode |
||
| 127 | */ |
||
| 128 | public function setLastResponse($data) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get current temperature. |
||
| 135 | * |
||
| 136 | * @param bool $withUnit return or not the unit |
||
| 137 | * |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function getTemperature($withUnit = false) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get Location. |
||
| 155 | * |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function getLocation() |
|
| 166 | |||
| 167 | /** |
||
| 168 | * get Forecast. |
||
| 169 | * |
||
| 170 | * @return array |
||
| 171 | */ |
||
| 172 | View Code Duplication | public function getForecast() |
|
| 180 | |||
| 181 | /** |
||
| 182 | * get Wind. |
||
| 183 | * |
||
| 184 | * @param bool $withUnit return or not the unit |
||
| 185 | * |
||
| 186 | * @return array |
||
| 187 | */ |
||
| 188 | public function getWind($withUnit = false) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param GoutteClient $client |
||
| 209 | */ |
||
| 210 | public function setClient(GoutteClient $client) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function getWoeid() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function getCity() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | public function getYql() |
||
| 238 | } |
||
| 239 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..