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 |
||
| 11 | class OracleGrammar extends Grammar |
||
| 12 | { |
||
| 13 | use OracleReservedWords; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The keyword identifier wrapper format. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $wrapper = '%s'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The possible column modifiers. |
||
| 24 | * |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | protected $modifiers = ['Increment', 'Nullable', 'Default']; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The possible column serials |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger']; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $schema_prefix = ''; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * If this Grammar supports schema changes wrapped in a transaction. |
||
| 43 | * |
||
| 44 | * @var bool |
||
| 45 | */ |
||
| 46 | protected $transactions = true; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Compile a create table command. |
||
| 50 | * |
||
| 51 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 52 | * @param \Illuminate\Support\Fluent $command |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 30 | public function compileCreate(Blueprint $blueprint, Fluent $command) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Wrap a table in keyword identifiers. |
||
| 78 | * |
||
| 79 | * @param mixed $table |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | 177 | public function wrapTable($table) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Get the schema prefix. |
||
| 89 | * |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | 177 | public function getSchemaPrefix() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * Set the schema prefix. |
||
| 99 | * |
||
| 100 | * @param string $prefix |
||
| 101 | */ |
||
| 102 | public function setSchemaPrefix($prefix) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Get the foreign key syntax for a table creation statement. |
||
| 109 | * |
||
| 110 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 111 | * @return string |
||
| 112 | */ |
||
| 113 | 30 | protected function addForeignKeys(Blueprint $blueprint) |
|
| 141 | |||
| 142 | /** |
||
| 143 | * Get the primary key syntax for a table creation statement. |
||
| 144 | * |
||
| 145 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 146 | * @return string|null |
||
| 147 | */ |
||
| 148 | 120 | protected function addPrimaryKeys(Blueprint $blueprint) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Compile the query to determine if a table exists. |
||
| 163 | * |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | 3 | public function compileTableExists() |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Compile the query to determine the list of columns. |
||
| 173 | * |
||
| 174 | * @param string $database |
||
| 175 | * @param string $table |
||
| 176 | * @return string |
||
| 177 | */ |
||
| 178 | 3 | public function compileColumnExists($database, $table) |
|
| 182 | |||
| 183 | /** |
||
| 184 | * Compile an add column command. |
||
| 185 | * |
||
| 186 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 187 | * @param \Illuminate\Support\Fluent $command |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | 90 | public function compileAdd(Blueprint $blueprint, Fluent $command) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Compile a primary key command. |
||
| 203 | * |
||
| 204 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 205 | * @param \Illuminate\Support\Fluent $command |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | 27 | public function compilePrimary(Blueprint $blueprint, Fluent $command) |
|
| 220 | |||
| 221 | /** |
||
| 222 | * Compile a foreign key command. |
||
| 223 | * |
||
| 224 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 225 | * @param \Illuminate\Support\Fluent $command |
||
| 226 | * @return string|void |
||
| 227 | */ |
||
| 228 | 15 | public function compileForeign(Blueprint $blueprint, Fluent $command) |
|
| 258 | |||
| 259 | /** |
||
| 260 | * Compile a unique key command. |
||
| 261 | * |
||
| 262 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 263 | * @param \Illuminate\Support\Fluent $command |
||
| 264 | * @return string |
||
| 265 | */ |
||
| 266 | 9 | public function compileUnique(Blueprint $blueprint, Fluent $command) |
|
| 270 | |||
| 271 | /** |
||
| 272 | * Compile a plain index key command. |
||
| 273 | * |
||
| 274 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 275 | * @param \Illuminate\Support\Fluent $command |
||
| 276 | * @return string |
||
| 277 | */ |
||
| 278 | 3 | public function compileIndex(Blueprint $blueprint, Fluent $command) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Compile a drop table command. |
||
| 285 | * |
||
| 286 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 287 | * @param \Illuminate\Support\Fluent $command |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | 6 | public function compileDrop(Blueprint $blueprint, Fluent $command) |
|
| 294 | |||
| 295 | /** |
||
| 296 | * Compile a drop table (if exists) command. |
||
| 297 | * |
||
| 298 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 299 | * @param \Illuminate\Support\Fluent $command |
||
| 300 | * @return string |
||
| 301 | */ |
||
| 302 | public function compileDropIfExists(Blueprint $blueprint, Fluent $command) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Compile a drop column command. |
||
| 317 | * |
||
| 318 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 319 | * @param \Illuminate\Support\Fluent $command |
||
| 320 | * @return string |
||
| 321 | */ |
||
| 322 | 6 | public function compileDropColumn(Blueprint $blueprint, Fluent $command) |
|
| 330 | |||
| 331 | /** |
||
| 332 | * Compile a drop primary key command. |
||
| 333 | * |
||
| 334 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 335 | * @param \Illuminate\Support\Fluent $command |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | 3 | public function compileDropPrimary(Blueprint $blueprint, Fluent $command) |
|
| 342 | |||
| 343 | /** |
||
| 344 | * @param Blueprint $blueprint |
||
| 345 | * @param Fluent $command |
||
| 346 | * @param string $type |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | 12 | private function dropConstraint(Blueprint $blueprint, Fluent $command, $type) |
|
| 360 | |||
| 361 | /** |
||
| 362 | * Compile a drop unique key command. |
||
| 363 | * |
||
| 364 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 365 | * @param \Illuminate\Support\Fluent $command |
||
| 366 | * @return string |
||
| 367 | */ |
||
| 368 | 3 | public function compileDropUnique(Blueprint $blueprint, Fluent $command) |
|
| 372 | |||
| 373 | /** |
||
| 374 | * Compile a drop index command. |
||
| 375 | * |
||
| 376 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 377 | * @param \Illuminate\Support\Fluent $command |
||
| 378 | * @return string |
||
| 379 | */ |
||
| 380 | 3 | public function compileDropIndex(Blueprint $blueprint, Fluent $command) |
|
| 384 | |||
| 385 | /** |
||
| 386 | * Compile a drop foreign key command. |
||
| 387 | * |
||
| 388 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 389 | * @param \Illuminate\Support\Fluent $command |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | 3 | public function compileDropForeign(Blueprint $blueprint, Fluent $command) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * Compile a rename table command. |
||
| 399 | * |
||
| 400 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 401 | * @param \Illuminate\Support\Fluent $command |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | 6 | public function compileRename(Blueprint $blueprint, Fluent $command) |
|
| 410 | |||
| 411 | /** |
||
| 412 | * Compile a rename column command. |
||
| 413 | * |
||
| 414 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 415 | * @param \Illuminate\Support\Fluent $command |
||
| 416 | * @param \Illuminate\Database\Connection $connection |
||
| 417 | * @return array |
||
| 418 | */ |
||
| 419 | public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Create the column definition for a char type. |
||
| 431 | * |
||
| 432 | * @param \Illuminate\Support\Fluent $column |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | 3 | protected function typeChar(Fluent $column) |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Create the column definition for a string type. |
||
| 442 | * |
||
| 443 | * @param \Illuminate\Support\Fluent $column |
||
| 444 | * @return string |
||
| 445 | */ |
||
| 446 | 42 | protected function typeString(Fluent $column) |
|
| 450 | |||
| 451 | /** |
||
| 452 | * Create column definition for a nvarchar type. |
||
| 453 | * |
||
| 454 | * @param \Illuminate\Support\Fluent $column |
||
| 455 | * @return string |
||
| 456 | */ |
||
| 457 | 3 | protected function typeNvarchar2(Fluent $column) |
|
| 461 | |||
| 462 | /** |
||
| 463 | * Create the column definition for a text type. |
||
| 464 | * |
||
| 465 | * @param \Illuminate\Support\Fluent $column |
||
| 466 | * @return string |
||
| 467 | */ |
||
| 468 | 3 | protected function typeText(Fluent $column) |
|
| 472 | |||
| 473 | /** |
||
| 474 | * Create the column definition for a medium text type. |
||
| 475 | * |
||
| 476 | * @param \Illuminate\Support\Fluent $column |
||
| 477 | * @return string |
||
| 478 | */ |
||
| 479 | 3 | protected function typeMediumText(Fluent $column) |
|
| 483 | |||
| 484 | /** |
||
| 485 | * Create the column definition for a long text type. |
||
| 486 | * |
||
| 487 | * @param \Illuminate\Support\Fluent $column |
||
| 488 | * @return string |
||
| 489 | */ |
||
| 490 | 3 | protected function typeLongText(Fluent $column) |
|
| 494 | |||
| 495 | /** |
||
| 496 | * Create the column definition for a integer type. |
||
| 497 | * |
||
| 498 | * @param \Illuminate\Support\Fluent $column |
||
| 499 | * @return string |
||
| 500 | */ |
||
| 501 | 48 | protected function typeInteger(Fluent $column) |
|
| 507 | |||
| 508 | /** |
||
| 509 | * Create the column definition for a integer type. |
||
| 510 | * |
||
| 511 | * @param \Illuminate\Support\Fluent $column |
||
| 512 | * @return string |
||
| 513 | */ |
||
| 514 | 3 | protected function typeBigInteger(Fluent $column) |
|
| 520 | |||
| 521 | /** |
||
| 522 | * Create the column definition for a medium integer type. |
||
| 523 | * |
||
| 524 | * @param \Illuminate\Support\Fluent $column |
||
| 525 | * @return string |
||
| 526 | */ |
||
| 527 | 3 | protected function typeMediumInteger(Fluent $column) |
|
| 533 | |||
| 534 | /** |
||
| 535 | * Create the column definition for a small integer type. |
||
| 536 | * |
||
| 537 | * @param \Illuminate\Support\Fluent $column |
||
| 538 | * @return string |
||
| 539 | */ |
||
| 540 | 3 | protected function typeSmallInteger(Fluent $column) |
|
| 546 | |||
| 547 | /** |
||
| 548 | * Create the column definition for a tiny integer type. |
||
| 549 | * |
||
| 550 | * @param \Illuminate\Support\Fluent $column |
||
| 551 | * @return string |
||
| 552 | */ |
||
| 553 | 3 | protected function typeTinyInteger(Fluent $column) |
|
| 559 | |||
| 560 | /** |
||
| 561 | * Create the column definition for a float type. |
||
| 562 | * |
||
| 563 | * @param \Illuminate\Support\Fluent $column |
||
| 564 | * @return string |
||
| 565 | */ |
||
| 566 | 3 | protected function typeFloat(Fluent $column) |
|
| 570 | |||
| 571 | /** |
||
| 572 | * Create the column definition for a double type. |
||
| 573 | * |
||
| 574 | * @param \Illuminate\Support\Fluent $column |
||
| 575 | * @return string |
||
| 576 | */ |
||
| 577 | 3 | protected function typeDouble(Fluent $column) |
|
| 581 | |||
| 582 | /** |
||
| 583 | * Create the column definition for a decimal type. |
||
| 584 | * |
||
| 585 | * @param \Illuminate\Support\Fluent $column |
||
| 586 | * @return string |
||
| 587 | */ |
||
| 588 | 3 | protected function typeDecimal(Fluent $column) |
|
| 592 | |||
| 593 | /** |
||
| 594 | * Create the column definition for a boolean type. |
||
| 595 | * |
||
| 596 | * @param \Illuminate\Support\Fluent $column |
||
| 597 | * @return string |
||
| 598 | */ |
||
| 599 | 3 | protected function typeBoolean(Fluent $column) |
|
| 603 | |||
| 604 | /** |
||
| 605 | * Create the column definition for a enum type. |
||
| 606 | * |
||
| 607 | * @param \Illuminate\Support\Fluent $column |
||
| 608 | * @return string |
||
| 609 | */ |
||
| 610 | 6 | protected function typeEnum(Fluent $column) |
|
| 616 | |||
| 617 | /** |
||
| 618 | * Create the column definition for a date type. |
||
| 619 | * |
||
| 620 | * @param \Illuminate\Support\Fluent $column |
||
| 621 | * @return string |
||
| 622 | */ |
||
| 623 | 3 | protected function typeDate(Fluent $column) |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Create the column definition for a date-time type. |
||
| 630 | * |
||
| 631 | * @param \Illuminate\Support\Fluent $column |
||
| 632 | * @return string |
||
| 633 | */ |
||
| 634 | 3 | protected function typeDateTime(Fluent $column) |
|
| 638 | |||
| 639 | /** |
||
| 640 | * Create the column definition for a time type. |
||
| 641 | * |
||
| 642 | * @param \Illuminate\Support\Fluent $column |
||
| 643 | * @return string |
||
| 644 | */ |
||
| 645 | 3 | protected function typeTime(Fluent $column) |
|
| 649 | |||
| 650 | /** |
||
| 651 | * Create the column definition for a timestamp type. |
||
| 652 | * |
||
| 653 | * @param \Illuminate\Support\Fluent $column |
||
| 654 | * @return string |
||
| 655 | */ |
||
| 656 | 9 | protected function typeTimestamp(Fluent $column) |
|
| 660 | |||
| 661 | /** |
||
| 662 | * Create the column definition for a timestamp type with timezone. |
||
| 663 | * |
||
| 664 | * @param Fluent $column |
||
| 665 | * @return string |
||
| 666 | */ |
||
| 667 | 6 | protected function typeTimestampTz(Fluent $column) |
|
| 671 | |||
| 672 | /** |
||
| 673 | * Create the column definition for a binary type. |
||
| 674 | * |
||
| 675 | * @param \Illuminate\Support\Fluent $column |
||
| 676 | * @return string |
||
| 677 | */ |
||
| 678 | 3 | protected function typeBinary(Fluent $column) |
|
| 682 | |||
| 683 | /** |
||
| 684 | * Get the SQL for a nullable column modifier. |
||
| 685 | * |
||
| 686 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 687 | * @param \Illuminate\Support\Fluent $column |
||
| 688 | * @return string |
||
| 689 | */ |
||
| 690 | 120 | protected function modifyNullable(Blueprint $blueprint, Fluent $column) |
|
| 707 | |||
| 708 | /** |
||
| 709 | * Get the SQL for a default column modifier. |
||
| 710 | * |
||
| 711 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 712 | * @param \Illuminate\Support\Fluent $column |
||
| 713 | * @return string |
||
| 714 | */ |
||
| 715 | 120 | protected function modifyDefault(Blueprint $blueprint, Fluent $column) |
|
| 720 | |||
| 721 | /** |
||
| 722 | * Get the SQL for an auto-increment column modifier. |
||
| 723 | * |
||
| 724 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
||
| 725 | * @param \Illuminate\Support\Fluent $column |
||
| 726 | * @return string|null |
||
| 727 | */ |
||
| 728 | 120 | protected function modifyIncrement(Blueprint $blueprint, Fluent $column) |
|
| 734 | |||
| 735 | /** |
||
| 736 | * Wrap a single string in keyword identifiers. |
||
| 737 | * |
||
| 738 | * @param string $value |
||
| 739 | * @return string |
||
| 740 | */ |
||
| 741 | 177 | protected function wrapValue($value) |
|
| 749 | } |
||
| 750 |