1 | <?php |
||
10 | class ConfigurationProcessorCommandHandler implements CommandHandlerInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var ConfigurationProcessor |
||
14 | */ |
||
15 | private $configurationProcessor; |
||
16 | |||
17 | /** |
||
18 | * ConfigurationProcessorCommandHandler constructor. |
||
19 | * |
||
20 | * @param ConfigurationProcessor $configurationProcessor |
||
21 | */ |
||
22 | 2 | public function __construct(ConfigurationProcessor $configurationProcessor) |
|
26 | |||
27 | /** |
||
28 | * @param CommandInterface|ConfigurationProcessorCommand $command |
||
29 | */ |
||
30 | 1 | 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: