1 | <?php |
||
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) |
||
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | public function __toString() |
||
52 | |||
53 | /** |
||
54 | * Return a clone of this object |
||
55 | * |
||
56 | * @return static |
||
57 | */ |
||
58 | public function getClone() |
||
62 | |||
63 | /** |
||
64 | * @return AdapterInterface |
||
65 | */ |
||
66 | public function getAdapter() |
||
70 | |||
71 | /** |
||
72 | * @param AdapterInterface $adapter |
||
73 | * |
||
74 | * @return static |
||
75 | */ |
||
76 | public function setAdapter(AdapterInterface $adapter) |
||
81 | |||
82 | /** |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getSchema() |
||
89 | |||
90 | /** |
||
91 | * @param string $schema |
||
92 | * |
||
93 | * @return static |
||
94 | */ |
||
95 | public function setSchema($schema) |
||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getTable() |
||
109 | |||
110 | /** |
||
111 | * @param string $table |
||
112 | * |
||
113 | * @return static |
||
114 | */ |
||
115 | public function setTable($table) |
||
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getFullName() |
||
129 | |||
130 | /** |
||
131 | * @return string[] |
||
132 | */ |
||
133 | public function getColumns() |
||
137 | |||
138 | /** |
||
139 | * @param string[] $columns |
||
140 | * |
||
141 | * @return static |
||
142 | */ |
||
143 | public function setColumns(array $columns) |
||
149 | } |
||
150 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.