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

Drop   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 8
c 1
b 0
f 1
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 2
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\Table;
13
14
use Cycle\Database\Driver\HandlerInterface;
15
use Cycle\Migrations\CapsuleInterface;
16
use Cycle\Migrations\Exception\Operation\TableException;
17
use Cycle\Migrations\Operation\AbstractOperation;
18
19
final class Drop extends AbstractOperation
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function execute(CapsuleInterface $capsule): void
25
    {
26
        $schema = $capsule->getSchema($this->getTable());
27
        $database = $this->database ?? '[default]';
0 ignored issues
show
Bug Best Practice introduced by
The property database does not exist on Cycle\Migrations\Operation\Table\Drop. Did you maybe forget to declare it?
Loading history...
28
29
        if (!$schema->exists()) {
30
            throw new TableException(
31
                "Unable to drop table '{$database}'.'{$this->getTable()}', table does not exists"
32
            );
33
        }
34
35
        $schema->declareDropped();
36
        $schema->save(HandlerInterface::DO_ALL);
37
    }
38
}
39