1 | <?php declare(strict_types=1); |
||
14 | final class AddProjectHandler |
||
15 | { |
||
16 | /** |
||
17 | * @var RequestService |
||
18 | */ |
||
19 | private $requestService; |
||
20 | |||
21 | /** |
||
22 | * @var Hydrator |
||
23 | */ |
||
24 | private $hydrator; |
||
25 | |||
26 | /** |
||
27 | * @param RequestService $requestService |
||
28 | * @param Hydrator $hydrator |
||
29 | */ |
||
30 | 1 | public function __construct(RequestService $requestService, Hydrator $hydrator) |
|
35 | |||
36 | /** |
||
37 | * @param AddProjectCommand $command |
||
38 | * @return PromiseInterface |
||
39 | */ |
||
40 | 1 | public function handle(AddProjectCommand $command): PromiseInterface |
|
59 | } |
||
60 |
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: