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

View::initialize()   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
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace yentu\database;
3
4
use yentu\database\DatabaseItem;
5
6
7
class View extends DatabaseItem implements Changeable, Initializable
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 initialize(): void
22
    {
23
        $this->definition = $this->getChangeLogger()->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->getChangeLogger()->/** @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->getChangeLogger()->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->getChangeLogger()->/** @scrutinizer ignore-call */ dropView($this->buildDescription());
Loading history...
33
        return $this;
34
    }
35
    
36
    public function definition($definition)
37
    {
38
        $this->addChange('definition', 'definition', $definition);
39
        
40
        if($this->isNew())
41
        {
42
            $this->getChangeLogger()->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

42
            $this->getChangeLogger()->/** @scrutinizer ignore-call */ addView($this->buildDescription());
Loading history...
43
        }
44
        return $this;
45
    }
46
    
47
    public function view($name)
48
    {
49
        DatabaseItem::purge();
0 ignored issues
show
introduced by
The method purge() does not exist on yentu\database\DatabaseItem. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

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

49
        DatabaseItem::/** @scrutinizer ignore-call */ 
50
                      purge();
Loading history...
50
        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

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