Passed
Pull Request — 3.x (#31)
by
unknown
14:21
created

Truncate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
1
<?php
2
3
namespace Cycle\Migrations\Operation\Table;
4
5
use Cycle\Migrations\CapsuleInterface;
6
use Cycle\Migrations\Exception\Operation\TableException;
7
use Cycle\Migrations\Operation\AbstractOperation;
8
9
final class Truncate extends AbstractOperation
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function execute(CapsuleInterface $capsule): void
15
    {
16
        $schema = $capsule->getSchema($this->getTable());
17
        $database = $this->database ?? '[default]';
0 ignored issues
show
Bug Best Practice introduced by
The property database does not exist on Cycle\Migrations\Operation\Table\Truncate. Did you maybe forget to declare it?
Loading history...
18
19
        if (!$schema->exists()) {
20
            throw new TableException(
21
                "Unable to truncate table '{$database}'.'{$this->getTable()}', table does not exists"
22
            );
23
        }
24
25
        $capsule->getDatabase()->execute(sprintf('TRUNCATE `%s`', $this->getTable()));
26
    }
27
}
28