Create   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Migrations\Operation\Table;
6
7
use Cycle\Database\Driver\HandlerInterface;
8
use Cycle\Migrations\CapsuleInterface;
9
use Cycle\Migrations\Exception\Operation\TableException;
10
use Cycle\Migrations\Operation\AbstractOperation;
11
12
final class Create extends AbstractOperation
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 256
    public function execute(CapsuleInterface $capsule): void
18
    {
19 256
        $schema = $capsule->getSchema($this->getTable());
20 256
        $database = $this->database ?? '[default]';
0 ignored issues
show
Bug Best Practice introduced by
The property database does not exist on Cycle\Migrations\Operation\Table\Create. Did you maybe forget to declare it?
Loading history...
21
22 256
        if ($schema->exists()) {
23 16
            throw new TableException(
24 16
                "Unable to create table '{$database}'.'{$this->getTable()}', table already exists"
25
            );
26
        }
27
28 248
        if (empty($schema->getColumns())) {
29 8
            throw new TableException(
30 8
                "Unable to create table '{$database}'.'{$this->getTable()}', no columns were added"
31
            );
32
        }
33
34 240
        $schema->save(HandlerInterface::DO_ALL);
35
    }
36
}
37