Failed Conditions
Push — chore/add-feature-tests ( 9637dd...e69874 )
by
unknown
13:44
created

Tables::getTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns;
6
7
use Illuminate\Support\Fluent;
8
9
trait Tables
10
{
11
    /**
12
     * Indicate that the table needs to be created.
13
     *
14
     * @param  array  $options
15
     * @return Fluent
16
     */
17
    public function create($options = [])
18
    {
19
        $parameters = [];
20
        $parameters['options'] = $options;
21
        $parameters['explanation'] = "Create '{$this->table}' table.";
22
        $parameters['handler'] = 'table';
23
24
        return $this->addCommand('create', $parameters);
0 ignored issues
show
Bug introduced by
It seems like addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        return $this->/** @scrutinizer ignore-call */ addCommand('create', $parameters);
Loading history...
25
    }
26
27
    public function executeCreateCommand($command)
28
    {
29
        if ($this->connection->pretending()) {
30
            $this->connection->logQuery('/* ' . $command->explanation . " */\n", []);
31
32
            return;
33
        }
34
        $options = $command->options;
35
36
        if ($this->keyGenerator !== 'traditional') {
37
            $options['keyOptions']['type'] = $this->keyGenerator;
38
        }
39
40
        if ($this->keyGenerator === 'autoincrement' && $this->incrementOffset !== 0) {
41
            $options['keyOptions']['offset'] = $this->incrementOffset;
42
        }
43
44
        if (!$this->schemaManager->hasCollection($this->table)) {
45
            $this->schemaManager->createCollection($this->table, $options);
46
        }
47
    }
48
}
49