1 | <?php |
||
7 | class Stack extends \SplDoublyLinkedList implements StackInterface |
||
8 | { |
||
9 | 834 | public function __construct() |
|
13 | |||
14 | /** |
||
15 | * @param mixed $value |
||
16 | * @throws \InvalidArgumentException |
||
17 | */ |
||
18 | 54 | private function typeCheck($value) |
|
24 | |||
25 | /** |
||
26 | * @see \ArrayAccess::offsetGet() |
||
27 | * @param int $offset |
||
28 | * @return \BitWasp\Buffertools\Buffer |
||
29 | */ |
||
30 | 486 | public function offsetGet($offset) |
|
35 | |||
36 | /** |
||
37 | * @see \ArrayAccess::offsetSet() |
||
38 | * @param int $offset |
||
39 | * @param Buffer $value |
||
40 | * @throws \InvalidArgumentException |
||
41 | */ |
||
42 | 36 | public function offsetSet($offset, $value) |
|
48 | |||
49 | /** |
||
50 | * @see \ArrayAccess::offsetExists() |
||
51 | * @param int $offset |
||
52 | * @return bool |
||
53 | */ |
||
54 | 6 | public function offsetExists($offset) |
|
59 | |||
60 | /** |
||
61 | * @see \ArrayAccess::offsetUnset() |
||
62 | * @param int $offset |
||
63 | */ |
||
64 | 36 | public function offsetUnset($offset) |
|
69 | |||
70 | /** |
||
71 | * @param int $first |
||
72 | * @param int $second |
||
73 | */ |
||
74 | 24 | public function swap($first, $second) |
|
81 | |||
82 | /** |
||
83 | * @param int $index |
||
84 | * @param Buffer $value |
||
85 | */ |
||
86 | 18 | public function add($index, $value) |
|
110 | |||
111 | /** |
||
112 | * @return int |
||
113 | */ |
||
114 | 684 | public function end() |
|
123 | } |
||
124 |
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: