1 | <?php |
||
11 | class JsonLintToolHandler implements CommandHandlerInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var JsonLintToolExecutor |
||
15 | */ |
||
16 | private $jsonLintToolExecutor; |
||
17 | /** |
||
18 | * @var QueryBus |
||
19 | */ |
||
20 | private $queryBus; |
||
21 | |||
22 | /** |
||
23 | * JsonLintTool constructor. |
||
24 | * |
||
25 | * @param JsonLintToolExecutor $jsonLintToolExecutor |
||
26 | * @param QueryBus $queryBus |
||
27 | */ |
||
28 | 3 | public function __construct( |
|
35 | |||
36 | /** |
||
37 | * @param array $files |
||
38 | * @param string $errorMessage |
||
39 | */ |
||
40 | 3 | private function execute(array $files, $errorMessage) |
|
48 | |||
49 | /** |
||
50 | * @param array $files |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | 3 | private function jsonFilesExists(array $files) |
|
58 | |||
59 | /** |
||
60 | * @param CommandInterface|JsonLintTool $command |
||
61 | */ |
||
62 | 3 | public function handle(CommandInterface $command) |
|
66 | } |
||
67 |
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: