1 | <?php |
||
15 | class ErrorHandler implements ErrorHandlerContract |
||
16 | { |
||
17 | /** |
||
18 | * @var \NunoMaduro\Collision\Contracts\Provider |
||
19 | */ |
||
20 | protected $provider; |
||
21 | |||
22 | /** |
||
23 | * Creates a new instance of the class. |
||
24 | * |
||
25 | * @param \NunoMaduro\Collision\Contracts\Provider|null $provider |
||
26 | */ |
||
27 | public function __construct(ProviderContract $provider = null) |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function register(): void |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function setOutput(OutputInterface $output): void |
||
48 | } |
||
49 |
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: