1 | <?php |
||
9 | class MonologResetter implements ResetterInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var Logger |
||
13 | */ |
||
14 | private $logger; |
||
15 | |||
16 | /** |
||
17 | * Constructor. |
||
18 | * |
||
19 | * @param Logger $logger |
||
20 | */ |
||
21 | 2 | public function __construct(Logger $logger) |
|
25 | |||
26 | /** |
||
27 | * {@inheritDoc} |
||
28 | */ |
||
29 | 2 | public function reset() |
|
34 | |||
35 | 2 | private function resetHandlers(array $handlers) |
|
41 | |||
42 | 2 | private function resetHandler(HandlerInterface $handler) |
|
68 | } |
||
69 |
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: