Passed
Push — main ( c93099...0e69d1 )
by James Ekow Abaka
17:15
created

Schema::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace yentu\database;
3
4
5
class Schema extends DatabaseItem implements Changeable, Initializable
6
{
7
    private string $name;
8
    private bool $isReference;
9
    
10
    public function __construct(string $name)
11
    {
12
        $this->name = $name;
13
    }
14
    
15
    #[\Override]
16
    public function initialize(): void
17
    {
18
        if(!$this->getChangeLogger()->doesSchemaExist($this->name)) {
0 ignored issues
show
Bug introduced by
The method doesSchemaExist() does not exist on yentu\ChangeLogger. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

18
        if(!$this->getChangeLogger()->/** @scrutinizer ignore-call */ doesSchemaExist($this->name)) {
Loading history...
19
            $this->getChangeLogger()->addSchema($this->name);
0 ignored issues
show
Bug introduced by
The method addSchema() does not exist on yentu\ChangeLogger. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

19
            $this->getChangeLogger()->/** @scrutinizer ignore-call */ addSchema($this->name);
Loading history...
20
        }   
21
    }
22
    
23
    public function isReference(): bool
24
    {
25
        return $this->isReference;
26
    }
27
    
28
    public function setIsReference(bool $isReference): void
29
    {
30
        $this->isReference = $isReference;
31
    }
32
    
33
    public function table($name): Table
34
    {
35
        if($this->isReference) {
36
            $table = new Table($name, $this);
37
        } else {
38
            $table = $this->create('table', $name, $this);
0 ignored issues
show
Bug introduced by
The method create() does not exist on yentu\database\Schema. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

38
            /** @scrutinizer ignore-call */ 
39
            $table = $this->create('table', $name, $this);
Loading history...
39
        }
40
        $table->setIsReference($this->isReference);
41
        return $table;
42
    }
43
    
44
    public function view($name)
45
    {
46
        return $this->create('view', $name, $this);
47
    }
48
    
49
    public function getName()
50
    {
51
        return $this->name;
52
    }
53
54
    #[\Override]
55
    public function buildDescription() {
56
        return array(
57
            'name' => $this->name
58
        );
59
    }
60
}
61
62