Drop::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Migrations\Operation\ForeignKey;
6
7
use Cycle\Migrations\CapsuleInterface;
8
use Cycle\Migrations\Exception\Operation\ForeignKeyException;
9
10
final class Drop extends ForeignKey
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 24
    public function execute(CapsuleInterface $capsule): void
16
    {
17 24
        $schema = $capsule->getSchema($this->getTable());
18
19 24
        if (!$schema->hasForeignKey($this->columns)) {
20 8
            throw new ForeignKeyException(
21 8
                "Unable to drop foreign key '{$schema->getName()}'.'{$this->columnNames()}', "
22
                . 'foreign key does not exists'
23
            );
24
        }
25
26 16
        $schema->dropForeignKey($this->columns);
27
    }
28
}
29