1 | <?php |
||
23 | class NativeRegex extends SimpleLexer |
||
24 | { |
||
25 | /** |
||
26 | * NativeRegex constructor. |
||
27 | * @param array $tokens |
||
28 | * @param array $skip |
||
29 | */ |
||
30 | 3 | public function __construct(array $tokens = [], array $skip = []) |
|
35 | |||
36 | /** |
||
37 | * @param Readable $file |
||
38 | * @return \Traversable |
||
39 | * @throws \InvalidArgumentException |
||
40 | * @throws \RuntimeException |
||
41 | */ |
||
42 | 6 | protected function exec(Readable $file): \Traversable |
|
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 6 | private function getPattern(): string |
|
70 | |||
71 | /** |
||
72 | * @param \Traversable|\Generator $iterator |
||
73 | * @param int $offset |
||
74 | * @return Unknown |
||
75 | */ |
||
76 | 1 | private function unknown(\Traversable $iterator, int $offset): TokenInterface |
|
85 | |||
86 | /** |
||
87 | * @param \Traversable|\Iterator $iterator |
||
88 | * @param string $key |
||
89 | * @return string |
||
90 | */ |
||
91 | 1 | protected function reduce(\Traversable $iterator, string $key): string |
|
107 | |||
108 | /** |
||
109 | * @param \Traversable|\Iterator $iterator |
||
110 | * @param int $offset |
||
111 | * @return Token |
||
112 | */ |
||
113 | 6 | private function token(\Traversable $iterator, int $offset): TokenInterface |
|
121 | } |
||
122 |
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: