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

View::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
namespace yentu\database;
3
4
/**
5
 * @todo In future make the view definitions changeable
6
 */
7
class View extends \yentu\database\DatabaseItem
8
{
9
    private $name;
10
    private $schema;
11
    
12
    public $definition;
13
    
14
    public function __construct($name, $schema) 
15
    {
16
        $this->name = $name;
17
        $this->schema = $schema;
18
    }
19
    
20
    #[\Override]
21
    public function init()
22
    {
23
        $this->definition = $this->getDriver()->doesViewExist($this->buildDescription());
0 ignored issues
show
Bug introduced by
The method doesViewExist() 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

23
        $this->definition = $this->getDriver()->/** @scrutinizer ignore-call */ doesViewExist($this->buildDescription());
Loading history...
24
        if($this->definition === false)
25
        {
26
            $this->new = true;
27
        }        
28
    }
29
    
30
    public function drop()
31
    {
32
        $this->getDriver()->dropView($this->buildDescription());
0 ignored issues
show
Bug introduced by
The method dropView() 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

32
        $this->getDriver()->/** @scrutinizer ignore-call */ dropView($this->buildDescription());
Loading history...
33
        return $this;
34
    }
35
    
36
    public function commitNew() 
37
    {
38
        
39
    }
40
    
41
    public function definition($definition)
42
    {
43
        $this->addChange('definition', 'definition', $definition);
44
        
45
        if($this->isNew())
46
        {
47
            $this->getDriver()->addView($this->buildDescription());
0 ignored issues
show
Bug introduced by
The method addView() 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

47
            $this->getDriver()->/** @scrutinizer ignore-call */ addView($this->buildDescription());
Loading history...
48
        }
49
        return $this;
50
    }
51
    
52
    public function view($name)
53
    {
54
        DatabaseItem::purge();
0 ignored issues
show
Bug introduced by
The method purge() does not exist on yentu\database\DatabaseItem. Since it exists in all sub-types, consider adding an abstract or default implementation to yentu\database\DatabaseItem. ( Ignorable by Annotation )

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

54
        DatabaseItem::/** @scrutinizer ignore-call */ 
55
                      purge();
Loading history...
55
        return $this->create('view', $name, $this->schema);
0 ignored issues
show
Bug introduced by
The method create() does not exist on yentu\database\View. 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

55
        return $this->/** @scrutinizer ignore-call */ create('view', $name, $this->schema);
Loading history...
56
    }
57
    
58
    public function table($name)
59
    {
60
        DatabaseItem::purge();
61
        return $this->create('table', $name, $this->schema);
62
    }
63
    
64
    #[\Override]
65
    protected function buildDescription() {
66
        return array(
67
            'name' => $this->name,
68
            'schema' => $this->schema->getName(),
69
            'definition' => $this->definition
70
        );
71
    }    
72
}
73