Complex classes like Connection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Connection, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class Connection extends \Illuminate\Database\Connection |
||
11 | { |
||
12 | const DEFAULT_PAGE_SIZE = 5000; |
||
13 | |||
14 | /** |
||
15 | * The Cassandra keyspace |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $keyspace; |
||
20 | |||
21 | /** |
||
22 | * The Cassandra cluster |
||
23 | * |
||
24 | * @var \Cassandra\Cluster |
||
25 | */ |
||
26 | protected $cluster; |
||
27 | |||
28 | /** |
||
29 | * The Cassandra connection handler. |
||
30 | * |
||
31 | * @var \Cassandra\Session |
||
32 | */ |
||
33 | protected $session; |
||
34 | |||
35 | /** |
||
36 | * The config |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $config; |
||
41 | |||
42 | /** |
||
43 | * Create a new database connection instance. |
||
44 | * |
||
45 | * @param array $config |
||
46 | */ |
||
47 | public function __construct(array $config) |
||
70 | |||
71 | /** |
||
72 | * Begin a fluent query against a database table. |
||
73 | * |
||
74 | * @param string $table |
||
75 | * @return Query\Builder |
||
76 | */ |
||
77 | public function table($table) |
||
85 | |||
86 | /** |
||
87 | * return Cassandra cluster. |
||
88 | * |
||
89 | * @return \Cassandra\Cluster |
||
90 | */ |
||
91 | public function getCassandraCluster() |
||
95 | |||
96 | /** |
||
97 | * return Cassandra Session. |
||
98 | * |
||
99 | * @return \Cassandra\Session |
||
100 | */ |
||
101 | public function getCassandraSession() |
||
105 | |||
106 | /** |
||
107 | * Return the Cassandra keyspace |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getKeyspace() |
||
115 | |||
116 | /** |
||
117 | * Create a new Cassandra cluster object. |
||
118 | * |
||
119 | * @param array $config |
||
120 | * |
||
121 | * @return \Cassandra\Cluster |
||
122 | */ |
||
123 | protected function createCluster(array $config) |
||
173 | |||
174 | /** |
||
175 | * Disconnect from the underlying Cassandra connection. |
||
176 | */ |
||
177 | public function disconnect() |
||
182 | |||
183 | /** |
||
184 | * Get the PDO driver name. |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function getDriverName() |
||
192 | |||
193 | /** |
||
194 | * Run a select statement against the database. |
||
195 | * |
||
196 | * @param string $query |
||
197 | * @param array $bindings |
||
198 | * @param bool $useReadPdo |
||
199 | * @param array $customOptions |
||
200 | * |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function select($query, $bindings = [], $useReadPdo = true, array $customOptions = []) |
||
207 | |||
208 | /** |
||
209 | * Run an bulk insert statement against the database. |
||
210 | * |
||
211 | * @param array $queries |
||
212 | * @param array $bindings |
||
213 | * @param int $type |
||
214 | * @param array $customOptions |
||
215 | * |
||
216 | * @return bool |
||
217 | */ |
||
218 | public function insertBulk($queries = [], $bindings = [], $type = Cassandra::BATCH_LOGGED, array $customOptions = []) |
||
222 | |||
223 | /** |
||
224 | * Execute a group of queries inside a batch statement against the database. |
||
225 | * |
||
226 | * @param array $queries |
||
227 | * @param array $bindings |
||
228 | * @param int $type |
||
229 | * @param array $customOptions |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function batchStatement($queries = [], $bindings = [], $type = Cassandra::BATCH_LOGGED, array $customOptions = []) |
||
250 | |||
251 | /** |
||
252 | * Execute an CQL statement and return the boolean result. |
||
253 | * |
||
254 | * @param string $query |
||
255 | * @param array $bindings |
||
256 | * @param array $customOptions |
||
257 | * |
||
258 | * @return mixed |
||
259 | */ |
||
260 | public function statement($query, $bindings = [], array $customOptions = []) |
||
264 | |||
265 | /** |
||
266 | * Because Cassandra is an eventually consistent database, it's not possible to obtain |
||
267 | * the affected count for statements so we're just going to return 0, based on the idea |
||
268 | * that if the query fails somehow, an exception will be thrown |
||
269 | * |
||
270 | * @param string $query |
||
271 | * @param array $bindings |
||
272 | * @param array $customOptions |
||
273 | * |
||
274 | * @return int |
||
275 | */ |
||
276 | public function affectingStatement($query, $bindings = [], array $customOptions = []) |
||
280 | |||
281 | /** |
||
282 | * @inheritdoc |
||
283 | */ |
||
284 | protected function getDefaultPostProcessor() |
||
288 | |||
289 | /** |
||
290 | * @inheritdoc |
||
291 | */ |
||
292 | protected function getDefaultQueryGrammar() |
||
296 | |||
297 | /** |
||
298 | * @inheritdoc |
||
299 | */ |
||
300 | protected function getDefaultSchemaGrammar() |
||
304 | |||
305 | /** |
||
306 | * Reconnect to the database if connection is missing. |
||
307 | * |
||
308 | * @return void |
||
309 | */ |
||
310 | protected function reconnectIfMissingConnection() |
||
316 | |||
317 | /** |
||
318 | * Dynamically pass methods to the connection. |
||
319 | * |
||
320 | * @param string $method |
||
321 | * @param array $parameters |
||
322 | * @return mixed |
||
323 | */ |
||
324 | public function __call($method, $parameters) |
||
328 | |||
329 | /** |
||
330 | * Execute an CQL statement and return the boolean result. |
||
331 | * |
||
332 | * @param string $query |
||
333 | * @param array $bindings |
||
334 | * @param array $customOptions |
||
335 | * @param mixed $defaultFailed |
||
336 | * @param mixed $defaultSuccess |
||
337 | * |
||
338 | * @return mixed |
||
339 | */ |
||
340 | protected function runStatement($query, $bindings = [], array $customOptions = [], $defaultFailed = [], $defaultSuccess = null) |
||
357 | |||
358 | /** |
||
359 | * @inheritDoc |
||
360 | */ |
||
361 | public function transaction() |
||
365 | |||
366 | /** |
||
367 | * @inheritDoc |
||
368 | */ |
||
369 | public function beginTransaction() |
||
373 | |||
374 | /** |
||
375 | * @inheritDoc |
||
376 | */ |
||
377 | public function commit() |
||
381 | |||
382 | /** |
||
383 | * @inheritDoc |
||
384 | */ |
||
385 | public function rollBack() |
||
389 | |||
390 | /** |
||
391 | * @inheritDoc |
||
392 | */ |
||
393 | public function transactionLevel() |
||
397 | |||
398 | //TODO: override isDoctrineAvailable method |
||
399 | //TODO: override getDoctrineColumn method |
||
400 | //TODO: override getDoctrineSchemaManager method |
||
401 | //TODO: override getDoctrineConnection method |
||
402 | //TODO: override getPdo method |
||
403 | //TODO: override getReadPdo method |
||
404 | //TODO: override setPdo method |
||
405 | //TODO: override setReadPdo method |
||
406 | //TODO: override setReconnector method |
||
407 | //TODO: override reconnect method |
||
408 | //TODO: override query method |
||
409 | |||
410 | //TODO: override bindValues method |
||
411 | //TODO: override cursor method |
||
412 | //TODO: override unprepared method |
||
413 | |||
414 | //TODO: check prepareBindings method |
||
415 | |||
416 | //TODO: provide interface for $this->session->executeAsync |
||
417 | //TODO: provide interface for $this->session->prepareAsync |
||
418 | //TODO: provide interface for $this->session->closeAsync |
||
419 | //TODO: provide interface for $this->session->schema |
||
420 | } |
||
421 |
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: