Passed
Push — main ( 3f5d4e...df4575 )
by James Ekow Abaka
01:53
created

Schema::init()   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
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace yentu\database;
4
5
6
class Schema extends DatabaseItem
7
{
8
    private $name;
9
    private $isReference;
10
    
11
    public function __construct($name)
12
    {
13
        $this->name = $name;
14
    }
15
    
16
    #[\Override]
17
    public function init()
18
    {
19
        if(!$this->getDriver()->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

19
        if(!$this->getDriver()->/** @scrutinizer ignore-call */ doesSchemaExist($this->name)) {        
Loading history...
20
            $this->getDriver()->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

20
            $this->getDriver()->/** @scrutinizer ignore-call */ addSchema($this->name);
Loading history...
21
        }   
22
    }
23
    
24
    public function isReference()
25
    {
26
        return $this->isReference;
27
    }
28
    
29
    public function setIsReference($isReference)
30
    {
31
        $this->isReference = $isReference;
32
    }
33
    
34
    public function table($name)
35
    {
36
        if($this->isReference) {
37
            $table = new Table($name, $this);
38
        } else {
39
            $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

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