1 | <?php |
||
13 | class RouteServiceProvider extends AbstractServiceProvider |
||
14 | { |
||
15 | protected $provides = [ |
||
16 | Request::class, |
||
17 | Response::class |
||
18 | ]; |
||
19 | |||
20 | /** |
||
21 | * Use the register method to register items with the container via the |
||
22 | * protected $this->container property or the `getContainer` method |
||
23 | * from the ContainerAwareTrait. |
||
24 | * |
||
25 | * @return void |
||
26 | */ |
||
27 | public function register() |
||
32 | } |
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: