1 | <?php |
||
10 | abstract class AbstractTable |
||
11 | { |
||
12 | const CROSS_JOIN = 'CROSS JOIN'; |
||
13 | const LEFT_JOIN = 'LEFT JOIN'; |
||
14 | const INNER_JOIN = 'INNER JOIN'; |
||
15 | |||
16 | const ROOT_FROM = 1; |
||
17 | const ROOT_UPDATE = 2; |
||
18 | const ROOT_INSERT = 3; |
||
19 | |||
20 | /** |
||
21 | * @var AbstractBuilder $qb |
||
22 | */ |
||
23 | private $qb; |
||
24 | |||
25 | /** |
||
26 | * @var string $tableAlias |
||
27 | */ |
||
28 | private $tableAlias; |
||
29 | |||
30 | /** |
||
31 | * @var string $joinType |
||
32 | */ |
||
33 | private $joinType; |
||
34 | |||
35 | /** |
||
36 | * @var int $root |
||
37 | */ |
||
38 | private $rootType; |
||
39 | |||
40 | /** |
||
41 | * @var string $joinOn |
||
42 | */ |
||
43 | private $joinOn; |
||
44 | |||
45 | /** |
||
46 | * @var bool $join |
||
47 | */ |
||
48 | private $join = false; |
||
49 | |||
50 | /** |
||
51 | * @param AbstractBuilder $qb |
||
52 | */ |
||
53 | 28 | public function __construct(AbstractBuilder $qb) |
|
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | 18 | public function __toString() |
|
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | abstract public function getTableName(); |
||
70 | |||
71 | /** |
||
72 | * @return AbstractBuilder |
||
73 | */ |
||
74 | 1 | public function getQueryBuilder() |
|
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | 26 | public function getAlias() |
|
86 | |||
87 | /** |
||
88 | * @param string $alias |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | 8 | public function setAlias($alias) |
|
98 | |||
99 | /** |
||
100 | * @return bool |
||
101 | */ |
||
102 | 26 | public function isJoin() |
|
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | 3 | public function getJoinType() |
|
114 | |||
115 | /** |
||
116 | * @param string $joinType |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | 3 | public function setJoinType($joinType) |
|
127 | |||
128 | /** |
||
129 | * @return bool |
||
130 | */ |
||
131 | public function isRoot() |
||
135 | |||
136 | /** |
||
137 | * @param int $rootType |
||
138 | * |
||
139 | * @return $this |
||
140 | */ |
||
141 | public function setRootType($rootType) |
||
147 | |||
148 | /** |
||
149 | * @return int |
||
150 | */ |
||
151 | public function getRootType() |
||
155 | |||
156 | /** |
||
157 | * @return string |
||
158 | */ |
||
159 | 18 | public function getAliasOrName() |
|
163 | |||
164 | /** |
||
165 | * @param string $clause |
||
166 | * |
||
167 | * @return $this |
||
168 | */ |
||
169 | 4 | public function addSelect($clause) |
|
175 | |||
176 | /** |
||
177 | * @param string $clause |
||
178 | * |
||
179 | * @return $this |
||
180 | */ |
||
181 | 2 | public function joinOn($clause) |
|
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | 26 | public function getJoinOn() |
|
195 | |||
196 | /** |
||
197 | * @param string $name |
||
198 | * |
||
199 | * @return string |
||
200 | */ |
||
201 | 18 | public function column($name) |
|
205 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: