1 | <?php |
||
17 | trait ChildNodeTrait |
||
18 | { |
||
19 | use EventEmitterTrait; |
||
20 | |||
21 | /** |
||
22 | * @internal |
||
23 | * |
||
24 | * @var ParentNodeInterface|ChildNodeInterface |
||
25 | * */ |
||
26 | private $parentNode; |
||
27 | |||
28 | private $locked = false; |
||
29 | |||
30 | /** |
||
31 | * Attaches component to registry. |
||
32 | * |
||
33 | * @param ParentNodeInterface $parent |
||
34 | * |
||
35 | * @return null |
||
36 | */ |
||
37 | final public function internalSetParent(ParentNodeInterface $parent) |
||
42 | |||
43 | final public function internalUnsetParent() |
||
48 | |||
49 | /** |
||
50 | * Returns parent node. |
||
51 | * |
||
52 | * @return ParentNodeInterface|null |
||
53 | */ |
||
54 | final public function parent() |
||
58 | |||
59 | /** |
||
60 | * @return ObjectCollection |
||
61 | */ |
||
62 | public function parents() |
||
76 | |||
77 | final public function detach() |
||
84 | |||
85 | final public function attachTo(ParentNodeInterface $parent) |
||
92 | |||
93 | public function onParentChange(callable $callback, $once = false) |
||
103 | |||
104 | private function checkParentRelation(ParentNodeInterface $parent = null) |
||
116 | |||
117 | public function lock() |
||
123 | |||
124 | public function unlock() |
||
130 | |||
131 | public function isLocked() |
||
135 | } |
||
136 |
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 implementation 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 interface: