These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace PhpGitHooks\Module\PhpUnit\Contract\CommandHandler; |
||
4 | |||
5 | use PhpGitHooks\Infrastructure\CommandBus\CommandBus\CommandHandlerInterface; |
||
6 | use PhpGitHooks\Infrastructure\CommandBus\CommandBus\CommandInterface; |
||
7 | use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageCommand; |
||
8 | use PhpGitHooks\Module\PhpUnit\Service\GuardCoverageTool; |
||
9 | |||
10 | class GuardCoverageToolCommandHandler implements CommandHandlerInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var GuardCoverageTool |
||
14 | */ |
||
15 | private $guardCoverageTool; |
||
16 | |||
17 | /** |
||
18 | * GuardCoverageToolCommandHandler constructor. |
||
19 | * |
||
20 | * @param GuardCoverageTool $guardCoverageTool |
||
21 | */ |
||
22 | 2 | public function __construct(GuardCoverageTool $guardCoverageTool) |
|
23 | { |
||
24 | 2 | $this->guardCoverageTool = $guardCoverageTool; |
|
25 | 2 | } |
|
26 | |||
27 | /** |
||
28 | * @param CommandInterface|GuardCoverageCommand $command |
||
29 | */ |
||
30 | 2 | public function handle(CommandInterface $command) |
|
31 | { |
||
32 | 2 | $this->guardCoverageTool->run($command->getWarningMessage()); |
|
0 ignored issues
–
show
|
|||
33 | 2 | } |
|
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: