Passed
Push — master ( 10a192...087136 )
by Aleksei
07:38 queued 05:42
created

Drop   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 17
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license MIT
7
 * @author  Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Migrations\Operation\ForeignKey;
13
14
use Cycle\Migrations\CapsuleInterface;
15
use Cycle\Migrations\Exception\Operation\ForeignKeyException;
16
17
final class Drop extends ForeignKey
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function execute(CapsuleInterface $capsule): void
23
    {
24
        $schema = $capsule->getSchema($this->getTable());
25
26
        if (!$schema->hasForeignKey($this->columns)) {
27
            throw new ForeignKeyException(
28
                "Unable to drop foreign key '{$schema->getName()}'.'{$this->columnNames()}', "
29
                . 'foreign key does not exists'
30
            );
31
        }
32
33
        $schema->dropForeignKey($this->columns);
34
    }
35
}
36