1 | <?php |
||
15 | class CommitMsgHandler implements CommandHandlerInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var MergeValidatorInterface |
||
19 | */ |
||
20 | private $mergeValidator; |
||
21 | /** |
||
22 | * @var QueryBus |
||
23 | */ |
||
24 | private $queryBus; |
||
25 | /** |
||
26 | * @var CommitMessageFinderInterface |
||
27 | */ |
||
28 | private $commitMessageFinder; |
||
29 | |||
30 | /** |
||
31 | * CommitMsgTool constructor. |
||
32 | * |
||
33 | * @param MergeValidatorInterface $mergeValidator |
||
34 | * @param QueryBus $queryBus |
||
35 | * @param CommitMessageFinderInterface $commitMessageFinder |
||
36 | */ |
||
37 | 2 | public function __construct( |
|
46 | |||
47 | /** |
||
48 | * @param InputInterface $input |
||
49 | * |
||
50 | * @throws InvalidCommitMessageException |
||
51 | */ |
||
52 | 2 | private function run(InputInterface $input) |
|
73 | |||
74 | /** |
||
75 | * @param string $regularExpression |
||
76 | * @param string $commitMessage |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 1 | private function isValidCommitMessage($regularExpression, $commitMessage) |
|
84 | |||
85 | /** |
||
86 | * @param CommandInterface|CommitMsg $command |
||
87 | */ |
||
88 | 2 | public function handle(CommandInterface $command) |
|
92 | } |
||
93 |
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: