Drop::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 12
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.1481
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Migrations\Operation\Column;
6
7
use Cycle\Migrations\CapsuleInterface;
8
use Cycle\Migrations\Exception\Operation\ColumnException;
9
use Cycle\Migrations\Operation\AbstractOperation;
10
11
final class Drop extends AbstractOperation
12
{
13 40
    public function __construct(string $table, private string $name)
14
    {
15 40
        parent::__construct($table);
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
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
            throw new ColumnException(
27
                "Unable to drop column '{$schema->getName()}'.'{$this->name}', column does not exists"
28
            );
29
        }
30
31
        //Declaring column
32 32
        $schema->dropColumn($this->name);
33
    }
34
}
35