Completed
Branch feature/pre-split (67216b)
by Anton
03:28
created

DropReference::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Migrations\Operations\References;
9
10
use Spiral\Migrations\CapsuleInterface;
11
use Spiral\Migrations\Exceptions\Operations\ReferenceException;
12
use Spiral\Migrations\Operations\ReferenceOperation;
13
14
class DropReference extends ReferenceOperation
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function execute(CapsuleInterface $capsule)
20
    {
21
        $schema = $capsule->getSchema($this->getTable(), $this->getDatabase());
22
23
        if (!$schema->hasForeign($this->column)) {
24
            throw new ReferenceException(
25
                "Unable to drop foreign key '{$schema->getName()}'.'{$this->column}', "
26
                . "foreign key does not exists"
27
            );
28
        }
29
30
        $schema->dropForeign($this->column);
31
    }
32
}