Complex classes like OracleGrammar 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 OracleGrammar, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class OracleGrammar extends Grammar |
||
13 | { |
||
14 | use OracleReservedWords; |
||
15 | |||
16 | /** |
||
17 | * The keyword identifier wrapper format. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $wrapper = '%s'; |
||
22 | |||
23 | /** |
||
24 | * The possible column modifiers. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $modifiers = ['Increment', 'Nullable', 'Default']; |
||
29 | |||
30 | /** |
||
31 | * The possible column serials. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger']; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $schema_prefix = ''; |
||
41 | |||
42 | /** |
||
43 | * If this Grammar supports schema changes wrapped in a transaction. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $transactions = true; |
||
48 | |||
49 | /** |
||
50 | * Compile a create table command. |
||
51 | * |
||
52 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
53 | * @param \Illuminate\Support\Fluent $command |
||
54 | * @return string |
||
55 | */ |
||
56 | 30 | public function compileCreate(Blueprint $blueprint, Fluent $command) |
|
76 | |||
77 | /** |
||
78 | * Wrap a table in keyword identifiers. |
||
79 | * |
||
80 | * @param mixed $table |
||
81 | * @return string |
||
82 | */ |
||
83 | 177 | public function wrapTable($table) |
|
87 | |||
88 | /** |
||
89 | * Get the schema prefix. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 177 | public function getSchemaPrefix() |
|
97 | |||
98 | /** |
||
99 | * Set the schema prefix. |
||
100 | * |
||
101 | * @param string $prefix |
||
102 | */ |
||
103 | public function setSchemaPrefix($prefix) |
||
107 | |||
108 | /** |
||
109 | * Get the foreign key syntax for a table creation statement. |
||
110 | * |
||
111 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
112 | * @return string |
||
113 | */ |
||
114 | 30 | protected function addForeignKeys(Blueprint $blueprint) |
|
142 | |||
143 | /** |
||
144 | * Get the primary key syntax for a table creation statement. |
||
145 | * |
||
146 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
147 | * @return string|null |
||
148 | */ |
||
149 | 120 | protected function addPrimaryKeys(Blueprint $blueprint) |
|
161 | |||
162 | /** |
||
163 | * Compile the query to determine if a table exists. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | 3 | public function compileTableExists() |
|
171 | |||
172 | /** |
||
173 | * Compile the query to determine the list of columns. |
||
174 | * |
||
175 | * @param string $database |
||
176 | * @param string $table |
||
177 | * @return string |
||
178 | */ |
||
179 | 3 | public function compileColumnExists($database, $table) |
|
183 | |||
184 | /** |
||
185 | * Compile an add column command. |
||
186 | * |
||
187 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
188 | * @param \Illuminate\Support\Fluent $command |
||
189 | * @return string |
||
190 | */ |
||
191 | 90 | public function compileAdd(Blueprint $blueprint, Fluent $command) |
|
201 | |||
202 | /** |
||
203 | * Compile a primary key command. |
||
204 | * |
||
205 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
206 | * @param \Illuminate\Support\Fluent $command |
||
207 | * @return string |
||
208 | */ |
||
209 | 27 | public function compilePrimary(Blueprint $blueprint, Fluent $command) |
|
221 | |||
222 | /** |
||
223 | * Compile a foreign key command. |
||
224 | * |
||
225 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
226 | * @param \Illuminate\Support\Fluent $command |
||
227 | * @return string|void |
||
228 | */ |
||
229 | 15 | public function compileForeign(Blueprint $blueprint, Fluent $command) |
|
259 | |||
260 | /** |
||
261 | * Compile a unique key command. |
||
262 | * |
||
263 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
264 | * @param \Illuminate\Support\Fluent $command |
||
265 | * @return string |
||
266 | */ |
||
267 | 9 | public function compileUnique(Blueprint $blueprint, Fluent $command) |
|
271 | |||
272 | /** |
||
273 | * Compile a plain index key command. |
||
274 | * |
||
275 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
276 | * @param \Illuminate\Support\Fluent $command |
||
277 | * @return string |
||
278 | */ |
||
279 | 3 | public function compileIndex(Blueprint $blueprint, Fluent $command) |
|
283 | |||
284 | /** |
||
285 | * Compile a drop table command. |
||
286 | * |
||
287 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
288 | * @param \Illuminate\Support\Fluent $command |
||
289 | * @return string |
||
290 | */ |
||
291 | 6 | public function compileDrop(Blueprint $blueprint, Fluent $command) |
|
295 | |||
296 | /** |
||
297 | * Compile a drop table (if exists) command. |
||
298 | * |
||
299 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
300 | * @param \Illuminate\Support\Fluent $command |
||
301 | * @return string |
||
302 | */ |
||
303 | public function compileDropIfExists(Blueprint $blueprint, Fluent $command) |
||
304 | { |
||
305 | $table = $this->wrapTable($blueprint); |
||
306 | |||
307 | return "declare c int; |
||
308 | begin |
||
309 | select count(*) into c from user_tables where table_name = upper('$table'); |
||
310 | if c = 1 then |
||
311 | execute immediate 'drop table $table'; |
||
312 | end if; |
||
313 | end;"; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * Compile a drop column command. |
||
318 | * |
||
319 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
320 | * @param \Illuminate\Support\Fluent $command |
||
321 | * @return string |
||
322 | */ |
||
323 | 6 | public function compileDropColumn(Blueprint $blueprint, Fluent $command) |
|
331 | |||
332 | /** |
||
333 | * Compile a drop primary key command. |
||
334 | * |
||
335 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
336 | * @param \Illuminate\Support\Fluent $command |
||
337 | * @return string |
||
338 | */ |
||
339 | 3 | public function compileDropPrimary(Blueprint $blueprint, Fluent $command) |
|
343 | |||
344 | /** |
||
345 | * @param Blueprint $blueprint |
||
346 | * @param Fluent $command |
||
347 | * @param string $type |
||
348 | * @return string |
||
349 | */ |
||
350 | 12 | private function dropConstraint(Blueprint $blueprint, Fluent $command, $type) |
|
361 | |||
362 | /** |
||
363 | * Compile a drop unique key command. |
||
364 | * |
||
365 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
366 | * @param \Illuminate\Support\Fluent $command |
||
367 | * @return string |
||
368 | */ |
||
369 | 3 | public function compileDropUnique(Blueprint $blueprint, Fluent $command) |
|
373 | |||
374 | /** |
||
375 | * Compile a drop index command. |
||
376 | * |
||
377 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
378 | * @param \Illuminate\Support\Fluent $command |
||
379 | * @return string |
||
380 | */ |
||
381 | 3 | public function compileDropIndex(Blueprint $blueprint, Fluent $command) |
|
385 | |||
386 | /** |
||
387 | * Compile a drop foreign key command. |
||
388 | * |
||
389 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
390 | * @param \Illuminate\Support\Fluent $command |
||
391 | * @return string |
||
392 | */ |
||
393 | 3 | public function compileDropForeign(Blueprint $blueprint, Fluent $command) |
|
397 | |||
398 | /** |
||
399 | * Compile a rename table command. |
||
400 | * |
||
401 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
402 | * @param \Illuminate\Support\Fluent $command |
||
403 | * @return string |
||
404 | */ |
||
405 | 6 | public function compileRename(Blueprint $blueprint, Fluent $command) |
|
411 | |||
412 | /** |
||
413 | * Compile a rename column command. |
||
414 | * |
||
415 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
416 | * @param \Illuminate\Support\Fluent $command |
||
417 | * @param \Illuminate\Database\Connection $connection |
||
418 | * @return array |
||
419 | */ |
||
420 | public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection) |
||
429 | |||
430 | /** |
||
431 | * Create the column definition for a char type. |
||
432 | * |
||
433 | * @param \Illuminate\Support\Fluent $column |
||
434 | * @return string |
||
435 | */ |
||
436 | 3 | protected function typeChar(Fluent $column) |
|
440 | |||
441 | /** |
||
442 | * Create the column definition for a string type. |
||
443 | * |
||
444 | * @param \Illuminate\Support\Fluent $column |
||
445 | * @return string |
||
446 | */ |
||
447 | 42 | protected function typeString(Fluent $column) |
|
451 | |||
452 | /** |
||
453 | * Create column definition for a nvarchar type. |
||
454 | * |
||
455 | * @param \Illuminate\Support\Fluent $column |
||
456 | * @return string |
||
457 | */ |
||
458 | 3 | protected function typeNvarchar2(Fluent $column) |
|
462 | |||
463 | /** |
||
464 | * Create the column definition for a text type. |
||
465 | * |
||
466 | * @param \Illuminate\Support\Fluent $column |
||
467 | * @return string |
||
468 | */ |
||
469 | 3 | protected function typeText(Fluent $column) |
|
473 | |||
474 | /** |
||
475 | * Create the column definition for a medium text type. |
||
476 | * |
||
477 | * @param \Illuminate\Support\Fluent $column |
||
478 | * @return string |
||
479 | */ |
||
480 | 3 | protected function typeMediumText(Fluent $column) |
|
484 | |||
485 | /** |
||
486 | * Create the column definition for a long text type. |
||
487 | * |
||
488 | * @param \Illuminate\Support\Fluent $column |
||
489 | * @return string |
||
490 | */ |
||
491 | 3 | protected function typeLongText(Fluent $column) |
|
495 | |||
496 | /** |
||
497 | * Create the column definition for a integer type. |
||
498 | * |
||
499 | * @param \Illuminate\Support\Fluent $column |
||
500 | * @return string |
||
501 | */ |
||
502 | 48 | protected function typeInteger(Fluent $column) |
|
508 | |||
509 | /** |
||
510 | * Create the column definition for a integer type. |
||
511 | * |
||
512 | * @param \Illuminate\Support\Fluent $column |
||
513 | * @return string |
||
514 | */ |
||
515 | 3 | protected function typeBigInteger(Fluent $column) |
|
521 | |||
522 | /** |
||
523 | * Create the column definition for a medium integer type. |
||
524 | * |
||
525 | * @param \Illuminate\Support\Fluent $column |
||
526 | * @return string |
||
527 | */ |
||
528 | 3 | protected function typeMediumInteger(Fluent $column) |
|
534 | |||
535 | /** |
||
536 | * Create the column definition for a small integer type. |
||
537 | * |
||
538 | * @param \Illuminate\Support\Fluent $column |
||
539 | * @return string |
||
540 | */ |
||
541 | 3 | protected function typeSmallInteger(Fluent $column) |
|
547 | |||
548 | /** |
||
549 | * Create the column definition for a tiny integer type. |
||
550 | * |
||
551 | * @param \Illuminate\Support\Fluent $column |
||
552 | * @return string |
||
553 | */ |
||
554 | 3 | protected function typeTinyInteger(Fluent $column) |
|
560 | |||
561 | /** |
||
562 | * Create the column definition for a float type. |
||
563 | * |
||
564 | * @param \Illuminate\Support\Fluent $column |
||
565 | * @return string |
||
566 | */ |
||
567 | 3 | protected function typeFloat(Fluent $column) |
|
571 | |||
572 | /** |
||
573 | * Create the column definition for a double type. |
||
574 | * |
||
575 | * @param \Illuminate\Support\Fluent $column |
||
576 | * @return string |
||
577 | */ |
||
578 | 3 | protected function typeDouble(Fluent $column) |
|
582 | |||
583 | /** |
||
584 | * Create the column definition for a decimal type. |
||
585 | * |
||
586 | * @param \Illuminate\Support\Fluent $column |
||
587 | * @return string |
||
588 | */ |
||
589 | 3 | protected function typeDecimal(Fluent $column) |
|
593 | |||
594 | /** |
||
595 | * Create the column definition for a boolean type. |
||
596 | * |
||
597 | * @param \Illuminate\Support\Fluent $column |
||
598 | * @return string |
||
599 | */ |
||
600 | 3 | protected function typeBoolean(Fluent $column) |
|
604 | |||
605 | /** |
||
606 | * Create the column definition for a enum type. |
||
607 | * |
||
608 | * @param \Illuminate\Support\Fluent $column |
||
609 | * @return string |
||
610 | */ |
||
611 | 6 | protected function typeEnum(Fluent $column) |
|
617 | |||
618 | /** |
||
619 | * Create the column definition for a date type. |
||
620 | * |
||
621 | * @param \Illuminate\Support\Fluent $column |
||
622 | * @return string |
||
623 | */ |
||
624 | 3 | protected function typeDate(Fluent $column) |
|
628 | |||
629 | /** |
||
630 | * Create the column definition for a date-time type. |
||
631 | * |
||
632 | * @param \Illuminate\Support\Fluent $column |
||
633 | * @return string |
||
634 | */ |
||
635 | 3 | protected function typeDateTime(Fluent $column) |
|
639 | |||
640 | /** |
||
641 | * Create the column definition for a time type. |
||
642 | * |
||
643 | * @param \Illuminate\Support\Fluent $column |
||
644 | * @return string |
||
645 | */ |
||
646 | 3 | protected function typeTime(Fluent $column) |
|
650 | |||
651 | /** |
||
652 | * Create the column definition for a timestamp type. |
||
653 | * |
||
654 | * @param \Illuminate\Support\Fluent $column |
||
655 | * @return string |
||
656 | */ |
||
657 | 9 | protected function typeTimestamp(Fluent $column) |
|
661 | |||
662 | /** |
||
663 | * Create the column definition for a timestamp type with timezone. |
||
664 | * |
||
665 | * @param Fluent $column |
||
666 | * @return string |
||
667 | */ |
||
668 | 6 | protected function typeTimestampTz(Fluent $column) |
|
672 | |||
673 | /** |
||
674 | * Create the column definition for a binary type. |
||
675 | * |
||
676 | * @param \Illuminate\Support\Fluent $column |
||
677 | * @return string |
||
678 | */ |
||
679 | 3 | protected function typeBinary(Fluent $column) |
|
683 | |||
684 | /** |
||
685 | * Create the column definition for a uuid type. |
||
686 | * |
||
687 | * @param \Illuminate\Support\Fluent $column |
||
688 | * @return string |
||
689 | */ |
||
690 | protected function typeUuid(Fluent $column) |
||
694 | 120 | ||
695 | 120 | /** |
|
696 | 6 | * Create the column definition for a json type. |
|
697 | 4 | * |
|
698 | * @param \Illuminate\Support\Fluent $column |
||
699 | 120 | * @return string |
|
700 | 120 | */ |
|
701 | protected function typeJson(Fluent $column) |
||
705 | |||
706 | 117 | /** |
|
707 | * Create the column definition for a jsonb type. |
||
708 | * |
||
709 | * @param \Illuminate\Support\Fluent $column |
||
710 | * @return string |
||
711 | */ |
||
712 | protected function typeJsonb(Fluent $column) |
||
716 | 120 | ||
717 | /** |
||
718 | * Get the SQL for a nullable column modifier. |
||
719 | 120 | * |
|
720 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
721 | * @param \Illuminate\Support\Fluent $column |
||
722 | * @return string |
||
723 | */ |
||
724 | protected function modifyNullable(Blueprint $blueprint, Fluent $column) |
||
741 | |||
742 | 177 | /** |
|
743 | * Get the SQL for a default column modifier. |
||
744 | 177 | * |
|
745 | 3 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
|
746 | * @param \Illuminate\Support\Fluent $column |
||
747 | * @return string |
||
748 | 177 | */ |
|
749 | protected function modifyDefault(Blueprint $blueprint, Fluent $column) |
||
754 | |||
755 | /** |
||
756 | * Get the SQL for an auto-increment column modifier. |
||
757 | * |
||
758 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
759 | * @param \Illuminate\Support\Fluent $column |
||
760 | * @return string|null |
||
761 | */ |
||
762 | protected function modifyIncrement(Blueprint $blueprint, Fluent $column) |
||
768 | |||
769 | /** |
||
770 | * Wrap a single string in keyword identifiers. |
||
771 | * |
||
772 | * @param string $value |
||
773 | * @return string |
||
774 | */ |
||
775 | protected function wrapValue($value) |
||
783 | } |
||
784 |