| 1 | <?php |
||
| 16 | class LogServiceProvider extends ServiceProvider |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Registers services on the given container. |
||
| 20 | * |
||
| 21 | * This method should only be used to configure services and parameters. |
||
| 22 | * It should not get services. |
||
| 23 | * |
||
| 24 | * @param Container $pimple A container instance |
||
| 25 | */ |
||
| 26 | public function register(Container $pimple) |
||
| 54 | |||
| 55 | public function formatLogConfig($app) |
||
| 99 | } |
||
| 100 |
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: