Passed
Pull Request — next (#137)
by Bas
04:08
created

Tables::executeCreateCommand()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6.2163

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 19
ccs 9
cts 11
cp 0.8182
crap 6.2163
rs 9.2222
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 52
    public function create($options = [])
18
    {
19 52
        $parameters = [];
20 52
        $parameters['options'] = array_merge(
21 52
            [
22 52
                'keyOptions' => config('arangodb.schema.keyOptions'),
23 52
            ],
24 52
            $options,
25 52
        );
26 52
        $parameters['explanation'] = "Create '{$this->table}' table.";
27 52
        $parameters['handler'] = 'table';
28
29 52
        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

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