TableNode::getAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Graze\DataDb;
4
5
use Graze\DataDb\Adapter\AdapterInterface;
6
7
class TableNode implements TableNodeInterface
8
{
9
    use SoftColumnTrait;
10
11
    /**
12
     * @var AdapterInterface
13
     */
14
    private $adapter;
15
16
    /**
17
     * @var string
18
     */
19
    private $schema;
20
21
    /**
22
     * @var string
23
     */
24
    private $table;
25
26
    /**
27
     * @var string
28
     */
29
    private $columns;
30
31
    /**
32
     * TableNode constructor.
33
     *
34
     * @param AdapterInterface $adapter
35
     * @param string           $schema
36
     * @param string           $table
37
     */
38
    public function __construct(AdapterInterface $adapter, $schema, $table)
39
    {
40
        $this->adapter = $adapter;
41
        $this->schema = $schema;
42
        $this->table = $table;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function __toString()
49
    {
50
        return $this->getFullName();
51
    }
52
53
    /**
54
     * Return a clone of this object
55
     *
56
     * @return static
57
     */
58
    public function getClone()
59
    {
60
        return clone $this;
61
    }
62
63
    /**
64
     * @return AdapterInterface
65
     */
66
    public function getAdapter()
67
    {
68
        return $this->adapter;
69
    }
70
71
    /**
72
     * @param AdapterInterface $adapter
73
     *
74
     * @return static
75
     */
76
    public function setAdapter(AdapterInterface $adapter)
77
    {
78
        $this->adapter = $adapter;
79
        return $this;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getSchema()
86
    {
87
        return $this->schema;
88
    }
89
90
    /**
91
     * @param string $schema
92
     *
93
     * @return static
94
     */
95
    public function setSchema($schema)
96
    {
97
        $this->schema = $schema;
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getTable()
106
    {
107
        return $this->table;
108
    }
109
110
    /**
111
     * @param string $table
112
     *
113
     * @return static
114
     */
115
    public function setTable($table)
116
    {
117
        $this->table = $table;
118
119
        return $this;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getFullName()
126
    {
127
        return sprintf('%s.%s', $this->getSchema(), $this->getTable());
128
    }
129
130
    /**
131
     * @return string[]
132
     */
133
    public function getColumns()
134
    {
135
        return $this->columns;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->columns; (string) is incompatible with the return type declared by the interface Graze\DataDb\TableNodeInterface::getColumns of type string[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
136
    }
137
138
    /**
139
     * @param string[] $columns
140
     *
141
     * @return static
142
     */
143
    public function setColumns(array $columns)
144
    {
145
        $this->columns = $columns;
0 ignored issues
show
Documentation Bug introduced by
It seems like $columns of type array<integer,string> is incompatible with the declared type string of property $columns.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
146
147
        return $this;
148
    }
149
}
150