| 1 | <?php |
||
| 10 | class PrePushToolCommandHandler implements CommandHandlerInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var PrePushTool |
||
| 14 | */ |
||
| 15 | private $prePushTool; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * PrePushToolCommandHandler constructor. |
||
| 19 | * |
||
| 20 | * @param PrePushTool $prePushTool |
||
| 21 | */ |
||
| 22 | 3 | public function __construct(PrePushTool $prePushTool) |
|
| 26 | |||
| 27 | /** |
||
| 28 | * @param CommandInterface|PrePushToolCommand $command |
||
| 29 | */ |
||
| 30 | 3 | public function handle(CommandInterface $command) |
|
| 34 | } |
||
| 35 |
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: