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 | /** |
||
17 | * @var AbstractBuilder $qb |
||
18 | */ |
||
19 | private $qb; |
||
20 | |||
21 | /** |
||
22 | * @var string $tableAlias |
||
23 | */ |
||
24 | private $tableAlias; |
||
25 | |||
26 | /** |
||
27 | * @var string $joinType |
||
28 | */ |
||
29 | private $joinType; |
||
30 | |||
31 | /** |
||
32 | * @var string $joinOn |
||
33 | */ |
||
34 | private $joinOn; |
||
35 | |||
36 | /** |
||
37 | * @var bool $join |
||
38 | */ |
||
39 | private $join = false; |
||
40 | |||
41 | /** |
||
42 | * @param AbstractBuilder $qb |
||
43 | */ |
||
44 | 30 | public function __construct(AbstractBuilder $qb) |
|
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | 20 | public function __toString() |
|
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | abstract public function getTableName(); |
||
61 | |||
62 | /** |
||
63 | * @return AbstractBuilder |
||
64 | */ |
||
65 | 1 | public function getQueryBuilder() |
|
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 28 | public function getAlias() |
|
77 | |||
78 | /** |
||
79 | * @param string $alias |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | 9 | public function setAlias($alias) |
|
89 | |||
90 | /** |
||
91 | * @return bool |
||
92 | */ |
||
93 | 28 | public function isJoin() |
|
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | 3 | public function getJoinType() |
|
105 | |||
106 | /** |
||
107 | * @param string $joinType |
||
108 | * |
||
109 | * @return $this |
||
110 | */ |
||
111 | 3 | public function setJoinType($joinType) |
|
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | 20 | public function getAliasOrName() |
|
126 | |||
127 | /** |
||
128 | * @param string $clause |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | 4 | public function addSelect($clause) |
|
138 | |||
139 | /** |
||
140 | * @param string $clause |
||
141 | * |
||
142 | * @return $this |
||
143 | */ |
||
144 | 2 | public function joinOn($clause) |
|
150 | |||
151 | /** |
||
152 | * @return string |
||
153 | */ |
||
154 | 28 | public function getJoinOn() |
|
158 | |||
159 | /** |
||
160 | * @param string $name |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | 20 | public function column($name) |
|
168 | } |
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: