1 | <?php |
||
15 | class ComposerToolHandler implements CommandHandlerInterface |
||
16 | { |
||
17 | const CHECKING_MESSAGE = 'Checking composer files'; |
||
18 | /** |
||
19 | * @var PreCommitOutputWriter |
||
20 | */ |
||
21 | private $outputMessage; |
||
22 | /** |
||
23 | * @var OutputInterface |
||
24 | */ |
||
25 | private $output; |
||
26 | /** |
||
27 | * @var QueryBus |
||
28 | */ |
||
29 | private $queryBus; |
||
30 | /** |
||
31 | * ComposerTool constructor. |
||
32 | * |
||
33 | * @param QueryBus $queryBus |
||
34 | * @param OutputInterface $output |
||
35 | */ |
||
36 | 3 | public function __construct( |
|
43 | |||
44 | /** |
||
45 | * @param CommandInterface|ComposerTool $command |
||
46 | */ |
||
47 | 3 | public function handle(CommandInterface $command) |
|
51 | |||
52 | /** |
||
53 | * @param array $files |
||
54 | * @param string $errorMessage |
||
55 | * |
||
56 | * @throws ComposerFilesNotFoundException |
||
57 | */ |
||
58 | 3 | private function execute(array $files, $errorMessage) |
|
74 | |||
75 | /** |
||
76 | * @param bool $jsonFile |
||
77 | * @param bool $lockFile |
||
78 | * @param string $errorMessage |
||
79 | * |
||
80 | * @throws ComposerFilesNotFoundException * |
||
81 | */ |
||
82 | 2 | private function executeTool($jsonFile, $lockFile, $errorMessage) |
|
90 | |||
91 | /** |
||
92 | * @param array $files |
||
93 | * |
||
94 | * @return ComposerFilesResponse |
||
95 | */ |
||
96 | 3 | private function getComposerFilesResponse(array $files) |
|
100 | } |
||
101 |
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: