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 | /** | ||
| 108 | * Returns a specific config key or the whole config array if not set. | ||
| 109 | * | ||
| 110 | * @throws InvalidException if the given key is not found in the configuration | ||
| 111 | * | ||
| 112 | * @return mixed Config value | ||
| 113 | */ | ||
| 114 | public function get(string $key) | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Returns boolean indicates if configuration has key. | ||
| 129 | */ | ||
| 130 | public function has(string $key): bool | ||
| 134 | |||
| 135 | /** | ||
| 136 | * Return all configuration. | ||
| 137 | */ | ||
| 138 | public function getAll(): array | ||
| 142 | |||
| 143 | /** | ||
| 144 | * @param string $key Key to set | ||
| 145 | * @param mixed $value Value | ||
| 146 | */ | ||
| 147 | public function set(string $key, $value): void | ||
| 151 | |||
| 152 | /** | ||
| 153 | * Add value to a key. If original value is not an array, value is wrapped. | ||
| 154 | * | ||
| 155 | * @param string $key Key to add | ||
| 156 | * @param mixed $value Value | ||
| 157 | */ | ||
| 158 | public function add(string $key, $value): void | ||
| 170 | |||
| 171 | private static function parseDsn(Url $dsn): array | ||
| 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: