| Conditions | 3 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 32 | public function execute(CapsuleInterface $capsule): void |
|
| 22 | { |
||
| 23 | 32 | $schema = $capsule->getSchema($this->getTable()); |
|
| 24 | |||
| 25 | 32 | if (!$schema->hasColumn($this->name)) { |
|
| 26 | 8 | throw new ColumnException( |
|
| 27 | 8 | "Unable to rename column '{$schema->getName()}'.'{$this->name}', column does not exists" |
|
| 28 | ); |
||
| 29 | } |
||
| 30 | |||
| 31 | 24 | if ($schema->hasColumn($this->newName)) { |
|
| 32 | 8 | throw new ColumnException( |
|
| 33 | 8 | sprintf( |
|
| 34 | "Unable to rename column '%s'.'%s', column '%s' already exists", |
||
| 35 | 8 | $schema->getName(), |
|
| 36 | 8 | $this->name, |
|
| 37 | 8 | $this->newName |
|
| 38 | ) |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | //Declaring column |
||
| 43 | 16 | $schema->renameColumn($this->name, $this->newName); |
|
| 44 | } |
||
| 46 |