Passed
Push — master ( 10a192...087136 )
by Aleksei
07:38 queued 05:42
created

Drop   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 9
c 1
b 0
f 1
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license MIT
7
 * @author  Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Migrations\Operation\Column;
13
14
use Cycle\Migrations\CapsuleInterface;
15
use Cycle\Migrations\Exception\Operation\ColumnException;
16
use Cycle\Migrations\Operation\AbstractOperation;
17
18
final class Drop extends AbstractOperation
19
{
20
    /**
21
     * Column name.
22
     *
23
     * @var string
24
     */
25
    private $name;
26
27
    /**
28
     * @param string $table
29
     * @param string $name
30
     */
31
    public function __construct(string $table, string $name)
32
    {
33
        parent::__construct($table);
34
        $this->name = $name;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function execute(CapsuleInterface $capsule): void
41
    {
42
        $schema = $capsule->getSchema($this->getTable());
43
44
        if (!$schema->hasColumn($this->name)) {
45
            throw new ColumnException(
46
                "Unable to drop column '{$schema->getName()}'.'{$this->name}', column does not exists"
47
            );
48
        }
49
50
        //Declaring column
51
        $schema->dropColumn($this->name);
52
    }
53
}
54