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 |
||
| 12 | class Client |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * $apiEndpoint. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | public $apiEndpoint = 'http://api.every8d.com/API21/HTTP'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * $credit. |
||
| 23 | * |
||
| 24 | * @var float |
||
| 25 | */ |
||
| 26 | public $credit = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * $userId. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $userId; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * $password. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $password; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * $httpClient. |
||
| 44 | * |
||
| 45 | * @var \Http\Client\HttpClient |
||
| 46 | */ |
||
| 47 | protected $httpClient; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * $messageFactory. |
||
| 51 | * |
||
| 52 | * @var \Http\Message\MessageFactory |
||
| 53 | */ |
||
| 54 | protected $messageFactory; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * __construct. |
||
| 58 | * |
||
| 59 | * @param string $userId |
||
| 60 | * @param string $password |
||
| 61 | * @param \Http\Client\HttpClient $httpClient |
||
| 62 | * @param \Http\Message\MessageFactory $messageFactory |
||
| 63 | */ |
||
| 64 | 6 | public function __construct($userId, $password, HttpClient $httpClient = null, MessageFactory $messageFactory = null) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * https. |
||
| 74 | * |
||
| 75 | * @return $this |
||
| 76 | */ |
||
| 77 | 2 | public function https() |
|
| 83 | |||
| 84 | /** |
||
| 85 | * send. |
||
| 86 | * |
||
| 87 | * @param array $params |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | 2 | public function send($params) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * sendMMS. |
||
| 111 | * |
||
| 112 | * @param array $params |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | 1 | public function sendMMS($params) |
|
| 135 | |||
| 136 | /** |
||
| 137 | * credit. |
||
| 138 | * |
||
| 139 | * @return float |
||
| 140 | */ |
||
| 141 | 4 | public function credit() |
|
| 158 | |||
| 159 | /** |
||
| 160 | * setCredit. |
||
| 161 | * |
||
| 162 | * @param string $credit |
||
| 163 | */ |
||
| 164 | 3 | protected function setCredit($credit) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * isValidResponse. |
||
| 173 | * |
||
| 174 | * @param string $response |
||
| 175 | * |
||
| 176 | * @return bool |
||
| 177 | */ |
||
| 178 | 5 | protected function isValidResponse($response) |
|
| 182 | |||
| 183 | /** |
||
| 184 | * doRequest. |
||
| 185 | * |
||
| 186 | * @param string $uri |
||
| 187 | * @param array $params |
||
| 188 | * |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | 5 | protected function doRequest($uri, $params) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * remapParams. |
||
| 206 | * |
||
| 207 | * @param array $params |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | 3 | protected function remapParams($params) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * parseResponse. |
||
| 247 | * |
||
| 248 | * @param array $response |
||
| 249 | * @return array |
||
| 250 | */ |
||
| 251 | 2 | protected function parseResponse($response) |
|
| 263 | } |
||
| 264 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: