Complex classes like Oci8Connection 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 Oci8Connection, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class Oci8Connection extends Connection |
||
24 | { |
||
25 | const RECONNECT_ERRORS = 'reconnect_errors'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $schema; |
||
31 | |||
32 | /** |
||
33 | * @var \Yajra\Oci8\Schema\Sequence |
||
34 | */ |
||
35 | protected $sequence; |
||
36 | |||
37 | /** |
||
38 | * @var \Yajra\Oci8\Schema\Trigger |
||
39 | */ |
||
40 | protected $trigger; |
||
41 | |||
42 | /** |
||
43 | * @param PDO|\Closure $pdo |
||
44 | * @param string $database |
||
45 | * @param string $tablePrefix |
||
46 | * @param array $config |
||
47 | */ |
||
48 | public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) |
||
54 | |||
55 | /** |
||
56 | * Get current schema. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getSchema() |
||
64 | |||
65 | /** |
||
66 | * Set current schema. |
||
67 | * |
||
68 | * @param string $schema |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function setSchema($schema) |
||
80 | |||
81 | /** |
||
82 | * Update oracle session variables. |
||
83 | * |
||
84 | * @param array $sessionVars |
||
85 | * @return $this |
||
86 | */ |
||
87 | public function setSessionVars(array $sessionVars) |
||
105 | |||
106 | /** |
||
107 | * Get sequence class. |
||
108 | * |
||
109 | * @return \Yajra\Oci8\Schema\Sequence |
||
110 | */ |
||
111 | public function getSequence() |
||
115 | |||
116 | /** |
||
117 | * Set sequence class. |
||
118 | * |
||
119 | * @param \Yajra\Oci8\Schema\Sequence $sequence |
||
120 | * @return \Yajra\Oci8\Schema\Sequence |
||
121 | */ |
||
122 | public function setSequence(Sequence $sequence) |
||
126 | |||
127 | /** |
||
128 | * Get oracle trigger class. |
||
129 | * |
||
130 | * @return \Yajra\Oci8\Schema\Trigger |
||
131 | */ |
||
132 | public function getTrigger() |
||
136 | |||
137 | /** |
||
138 | * Set oracle trigger class. |
||
139 | * |
||
140 | * @param \Yajra\Oci8\Schema\Trigger $trigger |
||
141 | * @return \Yajra\Oci8\Schema\Trigger |
||
142 | */ |
||
143 | public function setTrigger(Trigger $trigger) |
||
147 | |||
148 | /** |
||
149 | * Get a schema builder instance for the connection. |
||
150 | * |
||
151 | * @return \Yajra\Oci8\Schema\OracleBuilder |
||
152 | */ |
||
153 | public function getSchemaBuilder() |
||
161 | |||
162 | /** |
||
163 | * Get a new query builder instance. |
||
164 | * |
||
165 | * @return \Illuminate\Database\Query\Builder |
||
166 | */ |
||
167 | public function query() |
||
173 | |||
174 | /** |
||
175 | * Set oracle session date format. |
||
176 | * |
||
177 | * @param string $format |
||
178 | * @return $this |
||
179 | */ |
||
180 | public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS') |
||
189 | |||
190 | /** |
||
191 | * Get doctrine connection. |
||
192 | * |
||
193 | * @return \Doctrine\DBAL\Connection |
||
194 | */ |
||
195 | public function getDoctrineConnection() |
||
207 | |||
208 | /** |
||
209 | * Get doctrine driver. |
||
210 | * |
||
211 | * @return \Doctrine\DBAL\Driver\OCI8\Driver |
||
212 | */ |
||
213 | protected function getDoctrineDriver() |
||
217 | |||
218 | /** |
||
219 | * Execute a PL/SQL Function and return its value. |
||
220 | * Usage: DB::executeFunction('function_name(:binding_1,:binding_n)', [':binding_1' => 'hi', ':binding_n' => |
||
221 | * 'bye'], PDO::PARAM_LOB). |
||
222 | * |
||
223 | * @param string $functionName |
||
224 | * @param array $bindings (kvp array) |
||
225 | * @param int $returnType (PDO::PARAM_*) |
||
226 | * @param int $length |
||
227 | * @return mixed $returnType |
||
228 | */ |
||
229 | public function executeFunction($functionName, array $bindings = [], $returnType = PDO::PARAM_STR, $length = null) |
||
240 | |||
241 | /** |
||
242 | * Execute a PL/SQL Procedure and return its results. |
||
243 | * |
||
244 | * Usage: DB::executeProcedure($procedureName, $bindings). |
||
245 | * $bindings looks like: |
||
246 | * $bindings = [ |
||
247 | * 'p_userid' => $id |
||
248 | * ]; |
||
249 | * |
||
250 | * @param string $procedureName |
||
251 | * @param array $bindings |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function executeProcedure($procedureName, array $bindings = []) |
||
262 | |||
263 | /** |
||
264 | * Execute a PL/SQL Procedure and return its cursor result. |
||
265 | * Usage: DB::executeProcedureWithCursor($procedureName, $bindings). |
||
266 | * |
||
267 | * https://docs.oracle.com/cd/E17781_01/appdev.112/e18555/ch_six_ref_cur.htm#TDPPH218 |
||
268 | * |
||
269 | * @param string $procedureName |
||
270 | * @param array $bindings |
||
271 | * @param string $cursorName |
||
272 | * @return array |
||
273 | */ |
||
274 | public function executeProcedureWithCursor($procedureName, array $bindings = [], $cursorName = ':cursor') |
||
291 | |||
292 | /** |
||
293 | * Creates sql command to run a procedure with bindings. |
||
294 | * |
||
295 | * @param string $procedureName |
||
296 | * @param array $bindings |
||
297 | * @param string|bool $cursor |
||
298 | * @return string |
||
299 | */ |
||
300 | public function createSqlFromProcedure($procedureName, array $bindings, $cursor = false) |
||
311 | |||
312 | /** |
||
313 | * Creates statement from procedure. |
||
314 | * |
||
315 | * @param string $procedureName |
||
316 | * @param array $bindings |
||
317 | * @param string|bool $cursorName |
||
318 | * @return PDOStatement |
||
319 | */ |
||
320 | public function createStatementFromProcedure($procedureName, array $bindings, $cursorName = false) |
||
326 | |||
327 | /** |
||
328 | * Create statement from function. |
||
329 | * |
||
330 | * @param string $functionName |
||
331 | * @param array $bindings |
||
332 | * @return PDOStatement |
||
333 | */ |
||
334 | public function createStatementFromFunction($functionName, array $bindings) |
||
342 | |||
343 | /** |
||
344 | * Bind values to their parameters in the given statement. |
||
345 | * |
||
346 | * @param \PDOStatement $statement |
||
347 | * @param array $bindings |
||
348 | * @return void |
||
349 | */ |
||
350 | public function bindValues($statement, $bindings) |
||
359 | |||
360 | /** |
||
361 | * Get the default query grammar instance. |
||
362 | * |
||
363 | * @return \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar |
||
364 | */ |
||
365 | protected function getDefaultQueryGrammar() |
||
369 | |||
370 | /** |
||
371 | * Set the table prefix and return the grammar. |
||
372 | * |
||
373 | * @param \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar $grammar |
||
374 | * @return \Illuminate\Database\Grammar |
||
375 | */ |
||
376 | public function withTablePrefix(Grammar $grammar) |
||
380 | |||
381 | /** |
||
382 | * Set the schema prefix and return the grammar. |
||
383 | * |
||
384 | * @param \Illuminate\Database\Grammar|\Yajra\Oci8\Query\Grammars\OracleGrammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar $grammar |
||
385 | * @return \Illuminate\Database\Grammar |
||
386 | */ |
||
387 | public function withSchemaPrefix(Grammar $grammar) |
||
393 | |||
394 | /** |
||
395 | * Get config schema prefix. |
||
396 | * |
||
397 | * @return string |
||
398 | */ |
||
399 | protected function getConfigSchemaPrefix() |
||
403 | |||
404 | /** |
||
405 | * Get the default schema grammar instance. |
||
406 | * |
||
407 | * @return \Illuminate\Database\Grammar|\Yajra\Oci8\Schema\Grammars\OracleGrammar |
||
408 | */ |
||
409 | protected function getDefaultSchemaGrammar() |
||
413 | |||
414 | /** |
||
415 | * Get the default post processor instance. |
||
416 | * |
||
417 | * @return \Yajra\Oci8\Query\Processors\OracleProcessor |
||
418 | */ |
||
419 | protected function getDefaultPostProcessor() |
||
423 | |||
424 | /** |
||
425 | * Add bindings to statement. |
||
426 | * |
||
427 | * @param array $bindings |
||
428 | * @param PDOStatement $stmt |
||
429 | * @return PDOStatement |
||
430 | */ |
||
431 | public function addBindingsToStatement(PDOStatement $stmt, array $bindings) |
||
449 | |||
450 | /** |
||
451 | * Determine if the given exception was caused by a lost connection. |
||
452 | * |
||
453 | * @param \Exception $e |
||
454 | * @return bool |
||
455 | */ |
||
456 | protected function causedByLostConnection(Throwable $e) |
||
487 | } |
||
488 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.