| Conditions | 7 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 52 | public function execute(CapsuleInterface $capsule): void |
||
| 53 | { |
||
| 54 | $schema = $capsule->getSchema($this->getTable()); |
||
| 55 | |||
| 56 | if (!$schema->hasForeignKey($this->columns)) { |
||
| 57 | throw new ForeignKeyException( |
||
| 58 | "Unable to alter foreign key '{$schema->getName()}'.({$this->columnNames()}), " |
||
| 59 | . 'key does not exists' |
||
| 60 | ); |
||
| 61 | } |
||
| 62 | |||
| 63 | $outerSchema = $capsule->getSchema($this->foreignTable); |
||
| 64 | |||
| 65 | if ($this->foreignTable != $this->table && !$outerSchema->exists()) { |
||
| 66 | throw new ForeignKeyException( |
||
| 67 | "Unable to alter foreign key '{$schema->getName()}'.'{$this->columnNames()}', " |
||
| 68 | . "foreign table '{$this->foreignTable}' does not exists" |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | foreach ($this->foreignKeys as $fk) { |
||
| 74 | if ($this->foreignTable != $this->table && !$outerSchema->hasColumn($fk)) { |
||
| 75 | throw new ForeignKeyException( |
||
| 76 | "Unable to alter foreign key '{$schema->getName()}'.'{$this->columnNames()}'," |
||
| 77 | . " foreign column '{$this->foreignTable}'.'{$fk}' does not exists" |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | $foreignKey = $schema->foreignKey($this->columns)->references( |
||
| 83 | $this->foreignTable, |
||
| 84 | $this->foreignKeys |
||
| 85 | ); |
||
| 86 | |||
| 87 | /* |
||
| 88 | * We are allowing both formats "NO_ACTION" and "NO ACTION". |
||
| 89 | */ |
||
| 90 | |||
| 91 | $foreignKey->onDelete( |
||
| 92 | str_replace( |
||
| 93 | '_', |
||
| 94 | ' ', |
||
| 95 | $this->getOption('delete', ForeignKeyInterface::NO_ACTION) |
||
| 96 | ) |
||
| 97 | ); |
||
| 98 | |||
| 99 | $foreignKey->onUpdate( |
||
| 100 | str_replace( |
||
| 101 | '_', |
||
| 102 | ' ', |
||
| 103 | $this->getOption('update', ForeignKeyInterface::NO_ACTION) |
||
| 104 | ) |
||
| 108 |