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 ClientConfiguration |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Config with defaults. |
||
| 20 | * |
||
| 21 | * retryOnConflict: Use in \Elastica\Client::updateDocument |
||
| 22 | * bigintConversion: Set to true to enable the JSON bigint to string conversion option (see issue #717) |
||
| 23 | * |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | protected $configuration = [ |
||
| 27 | 'host' => null, |
||
| 28 | 'port' => null, |
||
| 29 | 'path' => null, |
||
| 30 | 'url' => null, |
||
| 31 | 'proxy' => null, |
||
| 32 | 'transport' => null, |
||
| 33 | 'persistent' => true, |
||
| 34 | 'timeout' => null, |
||
| 35 | 'connections' => [], // host, port, path, transport, compression, persistent, timeout, username, password, auth_type, config -> (curl, headers, url) |
||
| 36 | 'roundRobin' => false, |
||
| 37 | 'retryOnConflict' => 0, |
||
| 38 | 'bigintConversion' => false, |
||
| 39 | 'username' => null, |
||
| 40 | 'password' => null, |
||
| 41 | 'auth_type' => null, //basic, digest, gssnegotiate, ntlm |
||
| 42 | ]; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Create configuration. |
||
| 46 | * |
||
| 47 | * @param array $config Additional config |
||
| 48 | * |
||
| 49 | * @return ClientConfiguration |
||
| 50 | */ |
||
| 51 | public static function fromArray(array $config): self |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Create configuration from Dsn string. Example of valid DSN strings: |
||
| 63 | * - http://localhost |
||
| 64 | * - http://foo:bar@localhost:1234?timeout=4&persistant=false |
||
| 65 | * - pool(http://127.0.0.1 http://127.0.0.2/bar?timeout=4) |
||
| 66 | * |
||
| 67 | * @return ClientConfiguration |
||
| 68 | */ |
||
| 69 | public static function fromDsn(string $dsnString): self |
||
| 106 | |||
| 107 | private static function parseDsn(Url $dsn): array |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Returns a specific config key or the whole config array if not set. |
||
| 152 | * |
||
| 153 | * @throws InvalidException if the given key is not found in the configuration |
||
| 154 | * |
||
| 155 | * @return mixed Config value |
||
| 156 | */ |
||
| 157 | public function get(string $key) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Returns boolean indicates if configuration has key. |
||
| 172 | */ |
||
| 173 | public function has(string $key): bool |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Return all configuration. |
||
| 180 | */ |
||
| 181 | public function getAll(): array |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param string $key Key to set |
||
| 188 | * @param mixed $value Value |
||
| 189 | */ |
||
| 190 | public function set(string $key, $value): void |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Add value to a key. If original value is not an array, value is wrapped. |
||
| 197 | * |
||
| 198 | * @param string $key Key to add |
||
| 199 | * @param mixed $value Value |
||
| 200 | */ |
||
| 201 | public function add(string $key, $value): void |
||
| 213 | } |
||
| 214 |
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: