Completed
Branch feature/pre-split (e801ec)
by Anton
03:11
created

DropTable::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
rs 9.4285
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Migrations\Operations\Table;
9
10
use Spiral\Database\Entities\AbstractHandler;
11
use Spiral\Migrations\CapsuleInterface;
12
use Spiral\Migrations\Exceptions\Operations\TableException;
13
use Spiral\Migrations\Operations\TableOperation;
14
15 View Code Duplication
class DropTable extends TableOperation
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function execute(CapsuleInterface $capsule)
21
    {
22
        $schema = $capsule->getSchema($this->getDatabase(), $this->getTable());
23
        $database = $this->database ?? '[default]';
24
25
        if (!$schema->exists()) {
26
            throw new TableException(
27
                "Unable to drop table '{$database}'.'{$this->getTable()}', table does not exists"
28
            );
29
        }
30
31
        $schema->declareDropped();
32
        $schema->save(AbstractHandler::DO_ALL);
33
    }
34
}