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 |
||
| 15 | class Client extends \GuzzleHttp\Client |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @const string Version number |
||
| 19 | */ |
||
| 20 | const VERSION = '0.0.1'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Defaults to expecting that Apache Tomcat runs on port 8080 on localhost |
||
| 24 | * (127.0.0.1). |
||
| 25 | * |
||
| 26 | * @var array[] |
||
| 27 | */ |
||
| 28 | protected $options = [ |
||
| 29 | 'scheme' => 'https', |
||
| 30 | 'hostname' => 'localhost', |
||
| 31 | 'port' => '8080', |
||
| 32 | 'token' => null, |
||
| 33 | 'username' => null, |
||
| 34 | 'password' => null, |
||
| 35 | ]; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param $options array |
||
| 39 | */ |
||
| 40 | 3 | public function __construct($options = []) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Set the bearer token |
||
| 66 | * |
||
| 67 | * @param string $token Bearer Token from Auth request |
||
| 68 | */ |
||
| 69 | 1 | public function setBearerToken($token) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Authenticate and get Bearer token from SmartCall |
||
| 76 | * |
||
| 77 | * @param string $username |
||
| 78 | * @param string $password |
||
| 79 | * |
||
| 80 | * @throws Exception |
||
| 81 | * |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | View Code Duplication | public function auth($username, $password) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Authenticate and invalidates all the user allocated tokens |
||
| 117 | * |
||
| 118 | * @param string $username |
||
| 119 | * @param string $password |
||
| 120 | * |
||
| 121 | * @throws Exception |
||
| 122 | * |
||
| 123 | * @return array |
||
| 124 | */ |
||
| 125 | public function authDelete() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Authenticate and invalidates all the user allocated tokens |
||
| 152 | * |
||
| 153 | * @param string $username |
||
| 154 | * @param string $password |
||
| 155 | * |
||
| 156 | * @throws Exception |
||
| 157 | * |
||
| 158 | * @return array |
||
| 159 | */ |
||
| 160 | View Code Duplication | public function authFlush($username, $password) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Authenticate and gets the number of available session tokens |
||
| 193 | * |
||
| 194 | * @param string $username |
||
| 195 | * @param string $password |
||
| 196 | * |
||
| 197 | * @throws Exception |
||
| 198 | * |
||
| 199 | * @return array |
||
| 200 | */ |
||
| 201 | View Code Duplication | public function authToken($username, $password) |
|
| 231 | |||
| 232 | /** |
||
| 233 | * Test SmartCall is responding. |
||
| 234 | * |
||
| 235 | * @throws Exception |
||
| 236 | * |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | 1 | public function ping() |
|
| 255 | } |
||
| 256 |
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..