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 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 7
cts 7
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\Index;
6
7
use Cycle\Migrations\CapsuleInterface;
8
use Cycle\Migrations\Exception\Operation\IndexException;
9
10
final class Drop extends Index
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 40
    public function execute(CapsuleInterface $capsule): void
16
    {
17 40
        $schema = $capsule->getSchema($this->getTable());
18
19 40
        if (!$schema->hasIndex($this->columns)) {
20 8
            $columns = implode(',', $this->columns);
21 8
            throw new IndexException(
22 8
                "Unable to drop index '{$schema->getName()}'.({$columns}), index does not exists"
23
            );
24
        }
25
26 32
        $schema->dropIndex($this->columns);
27
    }
28
}
29