Drop   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 22
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
A __construct() 0 3 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