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 the SQL needed to drop all tables. |
||
298 | * |
||
299 | * @return string |
||
300 | */ |
||
301 | public function compileDropAllTables() |
||
314 | |||
315 | /** |
||
316 | * Compile a drop table (if exists) command. |
||
317 | * |
||
318 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
319 | * @param \Illuminate\Support\Fluent $command |
||
320 | * @return string |
||
321 | */ |
||
322 | public function compileDropIfExists(Blueprint $blueprint, Fluent $command) |
||
334 | |||
335 | /** |
||
336 | * Compile a drop column command. |
||
337 | * |
||
338 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
339 | 3 | * @param \Illuminate\Support\Fluent $command |
|
340 | * @return string |
||
341 | 3 | */ |
|
342 | public function compileDropColumn(Blueprint $blueprint, Fluent $command) |
||
350 | 12 | ||
351 | /** |
||
352 | 12 | * Compile a drop primary key command. |
|
353 | 12 | * |
|
354 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
355 | 12 | * @param \Illuminate\Support\Fluent $command |
|
356 | 3 | * @return string |
|
357 | */ |
||
358 | public function compileDropPrimary(Blueprint $blueprint, Fluent $command) |
||
362 | |||
363 | /** |
||
364 | * @param Blueprint $blueprint |
||
365 | * @param Fluent $command |
||
366 | * @param string $type |
||
367 | * @return string |
||
368 | */ |
||
369 | 3 | private function dropConstraint(Blueprint $blueprint, Fluent $command, $type) |
|
380 | |||
381 | 3 | /** |
|
382 | * Compile a drop unique key command. |
||
383 | 3 | * |
|
384 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
385 | * @param \Illuminate\Support\Fluent $command |
||
386 | * @return string |
||
387 | */ |
||
388 | public function compileDropUnique(Blueprint $blueprint, Fluent $command) |
||
392 | |||
393 | 3 | /** |
|
394 | * Compile a drop index command. |
||
395 | 3 | * |
|
396 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
397 | * @param \Illuminate\Support\Fluent $command |
||
398 | * @return string |
||
399 | */ |
||
400 | public function compileDropIndex(Blueprint $blueprint, Fluent $command) |
||
404 | |||
405 | 6 | /** |
|
406 | * Compile a drop foreign key command. |
||
407 | 6 | * |
|
408 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
409 | 6 | * @param \Illuminate\Support\Fluent $command |
|
410 | * @return string |
||
411 | */ |
||
412 | public function compileDropForeign(Blueprint $blueprint, Fluent $command) |
||
416 | |||
417 | /** |
||
418 | * Compile a rename table command. |
||
419 | * |
||
420 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
421 | * @param \Illuminate\Support\Fluent $command |
||
422 | * @return string |
||
423 | */ |
||
424 | public function compileRename(Blueprint $blueprint, Fluent $command) |
||
430 | |||
431 | /** |
||
432 | * Compile a rename column command. |
||
433 | * |
||
434 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
435 | * @param \Illuminate\Support\Fluent $command |
||
436 | 3 | * @param \Illuminate\Database\Connection $connection |
|
437 | * @return array |
||
438 | 3 | */ |
|
439 | public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection) |
||
448 | |||
449 | 42 | /** |
|
450 | * Create the column definition for a char type. |
||
451 | * |
||
452 | * @param \Illuminate\Support\Fluent $column |
||
453 | * @return string |
||
454 | */ |
||
455 | protected function typeChar(Fluent $column) |
||
459 | |||
460 | 3 | /** |
|
461 | * Create the column definition for a string type. |
||
462 | * |
||
463 | * @param \Illuminate\Support\Fluent $column |
||
464 | * @return string |
||
465 | */ |
||
466 | protected function typeString(Fluent $column) |
||
470 | |||
471 | 3 | /** |
|
472 | * Create column definition for a nvarchar type. |
||
473 | * |
||
474 | * @param \Illuminate\Support\Fluent $column |
||
475 | * @return string |
||
476 | */ |
||
477 | protected function typeNvarchar2(Fluent $column) |
||
481 | |||
482 | 3 | /** |
|
483 | * Create the column definition for a text type. |
||
484 | * |
||
485 | * @param \Illuminate\Support\Fluent $column |
||
486 | * @return string |
||
487 | */ |
||
488 | protected function typeText(Fluent $column) |
||
492 | |||
493 | 3 | /** |
|
494 | * Create the column definition for a medium text type. |
||
495 | * |
||
496 | * @param \Illuminate\Support\Fluent $column |
||
497 | * @return string |
||
498 | */ |
||
499 | protected function typeMediumText(Fluent $column) |
||
503 | |||
504 | 48 | /** |
|
505 | * Create the column definition for a long text type. |
||
506 | 48 | * |
|
507 | * @param \Illuminate\Support\Fluent $column |
||
508 | * @return string |
||
509 | */ |
||
510 | protected function typeLongText(Fluent $column) |
||
514 | |||
515 | 3 | /** |
|
516 | * Create the column definition for a integer type. |
||
517 | 3 | * |
|
518 | * @param \Illuminate\Support\Fluent $column |
||
519 | 3 | * @return string |
|
520 | */ |
||
521 | protected function typeInteger(Fluent $column) |
||
527 | |||
528 | 3 | /** |
|
529 | * Create the column definition for a integer type. |
||
530 | 3 | * |
|
531 | * @param \Illuminate\Support\Fluent $column |
||
532 | 3 | * @return string |
|
533 | */ |
||
534 | protected function typeBigInteger(Fluent $column) |
||
540 | |||
541 | 3 | /** |
|
542 | * Create the column definition for a medium integer type. |
||
543 | 3 | * |
|
544 | * @param \Illuminate\Support\Fluent $column |
||
545 | 3 | * @return string |
|
546 | */ |
||
547 | protected function typeMediumInteger(Fluent $column) |
||
553 | |||
554 | 3 | /** |
|
555 | * Create the column definition for a small integer type. |
||
556 | 3 | * |
|
557 | * @param \Illuminate\Support\Fluent $column |
||
558 | 3 | * @return string |
|
559 | */ |
||
560 | protected function typeSmallInteger(Fluent $column) |
||
566 | |||
567 | 3 | /** |
|
568 | * Create the column definition for a tiny integer type. |
||
569 | 3 | * |
|
570 | * @param \Illuminate\Support\Fluent $column |
||
571 | * @return string |
||
572 | */ |
||
573 | protected function typeTinyInteger(Fluent $column) |
||
579 | |||
580 | 3 | /** |
|
581 | * Create the column definition for a float type. |
||
582 | * |
||
583 | * @param \Illuminate\Support\Fluent $column |
||
584 | * @return string |
||
585 | */ |
||
586 | protected function typeFloat(Fluent $column) |
||
590 | |||
591 | 3 | /** |
|
592 | * Create the column definition for a double type. |
||
593 | * |
||
594 | * @param \Illuminate\Support\Fluent $column |
||
595 | * @return string |
||
596 | */ |
||
597 | protected function typeDouble(Fluent $column) |
||
601 | |||
602 | 3 | /** |
|
603 | * Create the column definition for a decimal type. |
||
604 | * |
||
605 | * @param \Illuminate\Support\Fluent $column |
||
606 | * @return string |
||
607 | */ |
||
608 | protected function typeDecimal(Fluent $column) |
||
612 | |||
613 | 6 | /** |
|
614 | * Create the column definition for a boolean type. |
||
615 | 6 | * |
|
616 | * @param \Illuminate\Support\Fluent $column |
||
617 | * @return string |
||
618 | */ |
||
619 | protected function typeBoolean(Fluent $column) |
||
623 | |||
624 | 3 | /** |
|
625 | * Create the column definition for a enum type. |
||
626 | 3 | * |
|
627 | * @param \Illuminate\Support\Fluent $column |
||
628 | * @return string |
||
629 | */ |
||
630 | protected function typeEnum(Fluent $column) |
||
636 | |||
637 | 3 | /** |
|
638 | * Create the column definition for a date type. |
||
639 | * |
||
640 | * @param \Illuminate\Support\Fluent $column |
||
641 | * @return string |
||
642 | */ |
||
643 | protected function typeDate(Fluent $column) |
||
647 | |||
648 | 3 | /** |
|
649 | * Create the column definition for a date-time type. |
||
650 | * |
||
651 | * @param \Illuminate\Support\Fluent $column |
||
652 | * @return string |
||
653 | */ |
||
654 | protected function typeDateTime(Fluent $column) |
||
658 | |||
659 | 9 | /** |
|
660 | * Create the column definition for a time type. |
||
661 | * |
||
662 | * @param \Illuminate\Support\Fluent $column |
||
663 | * @return string |
||
664 | */ |
||
665 | protected function typeTime(Fluent $column) |
||
669 | |||
670 | 6 | /** |
|
671 | * Create the column definition for a timestamp type. |
||
672 | * |
||
673 | * @param \Illuminate\Support\Fluent $column |
||
674 | * @return string |
||
675 | */ |
||
676 | protected function typeTimestamp(Fluent $column) |
||
680 | |||
681 | 3 | /** |
|
682 | * Create the column definition for a timestamp type with timezone. |
||
683 | * |
||
684 | * @param Fluent $column |
||
685 | * @return string |
||
686 | */ |
||
687 | protected function typeTimestampTz(Fluent $column) |
||
691 | 120 | ||
692 | /** |
||
693 | * Create the column definition for a binary type. |
||
694 | 120 | * |
|
695 | 120 | * @param \Illuminate\Support\Fluent $column |
|
696 | 6 | * @return string |
|
697 | 4 | */ |
|
698 | protected function typeBinary(Fluent $column) |
||
702 | 120 | ||
703 | 9 | /** |
|
704 | * Create the column definition for a uuid type. |
||
705 | * |
||
706 | 117 | * @param \Illuminate\Support\Fluent $column |
|
707 | * @return string |
||
708 | */ |
||
709 | protected function typeUuid(Fluent $column) |
||
713 | |||
714 | /** |
||
715 | * Create the column definition for a json type. |
||
716 | 120 | * |
|
717 | * @param \Illuminate\Support\Fluent $column |
||
718 | * @return string |
||
719 | 120 | */ |
|
720 | protected function typeJson(Fluent $column) |
||
724 | |||
725 | /** |
||
726 | * Create the column definition for a jsonb type. |
||
727 | * |
||
728 | * @param \Illuminate\Support\Fluent $column |
||
729 | 120 | * @return string |
|
730 | */ |
||
731 | 120 | protected function typeJsonb(Fluent $column) |
|
735 | |||
736 | /** |
||
737 | * Get the SQL for a nullable column modifier. |
||
738 | * |
||
739 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
740 | * @param \Illuminate\Support\Fluent $column |
||
741 | * @return string |
||
742 | 177 | */ |
|
743 | protected function modifyNullable(Blueprint $blueprint, Fluent $column) |
||
761 | |||
762 | /** |
||
763 | * Get the SQL for a default column modifier. |
||
764 | * |
||
765 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
766 | * @param \Illuminate\Support\Fluent $column |
||
767 | * @return string |
||
768 | */ |
||
769 | protected function modifyDefault(Blueprint $blueprint, Fluent $column) |
||
774 | |||
775 | /** |
||
776 | * Get the SQL for an auto-increment column modifier. |
||
777 | * |
||
778 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
779 | * @param \Illuminate\Support\Fluent $column |
||
780 | * @return string|null |
||
781 | */ |
||
782 | protected function modifyIncrement(Blueprint $blueprint, Fluent $column) |
||
788 | |||
789 | /** |
||
790 | * Wrap a single string in keyword identifiers. |
||
791 | * |
||
792 | * @param string $value |
||
793 | * @return string |
||
794 | */ |
||
795 | protected function wrapValue($value) |
||
803 | } |
||
804 |