Builder::recreateDatabase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Tonysm\LaravelParatest\Database\Schema;
4
5
use Tonysm\LaravelParatest\Database\Connector;
6
7
class Builder
8
{
9
    public function __construct(Connector $connector, GrammarFactory $grammars)
10
    {
11
        $this->connector = $connector;
0 ignored issues
show
Bug introduced by
The property connector does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
        $this->grammars = $grammars;
0 ignored issues
show
Bug introduced by
The property grammars does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
    }
14
15
    public function createDatabase(array $options)
16
    {
17
        $grammar = $this->grammars->make($options['driver']);
18
19
        return $this->connector->exec(
20
            $grammar->compileCreateDatabase($options)
21
        );
22
    }
23
24
    public function dropDatabase(array $options)
25
    {
26
        $grammar = $this->grammars->make($options['driver']);
27
28
        return $this->connector->exec(
29
            $grammar->compileDropDatabase($options['database'])
30
        );
31
    }
32
33
    public function recreateDatabase(array $options): void
34
    {
35
        $this->dropDatabase($options);
36
        $this->createDatabase($options);
37
    }
38
}
39