Drop::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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