1 | <?php |
||
13 | class PhpCsFixerToolHandler implements CommandHandlerInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var OutputInterface |
||
17 | */ |
||
18 | private $output; |
||
19 | /** |
||
20 | * @var PhpCsFixerToolProcessorInterface |
||
21 | */ |
||
22 | private $phpCsFixerToolProcessor; |
||
23 | |||
24 | /** |
||
25 | * PhpCsFixerTool constructor. |
||
26 | * |
||
27 | * @param OutputInterface $output |
||
28 | * @param PhpCsFixerToolProcessorInterface $phpCsFixerToolProcessor |
||
29 | */ |
||
30 | 2 | public function __construct(OutputInterface $output, PhpCsFixerToolProcessorInterface $phpCsFixerToolProcessor) |
|
35 | |||
36 | /** |
||
37 | * @param array $files |
||
38 | * @param bool $psr0 |
||
39 | * @param bool $psr1 |
||
40 | * @param bool $psr2 |
||
41 | * @param bool $symfony |
||
42 | * @param string $options |
||
43 | * @param string $errorMessage |
||
44 | */ |
||
45 | 2 | private function execute(array $files, $psr0, $psr1, $psr2, $symfony, $options, $errorMessage) |
|
63 | |||
64 | /** |
||
65 | * @param array $files |
||
66 | * @param string $level |
||
67 | * @param string $options |
||
68 | * @param string $errorMessage |
||
69 | * |
||
70 | * @throws PhpCsFixerViolationsException |
||
71 | */ |
||
72 | 2 | private function executeTool(array $files, $level, $options, $errorMessage) |
|
94 | |||
95 | /** |
||
96 | * @param CommandInterface|PhpCsFixerTool $command |
||
97 | */ |
||
98 | 2 | public function handle(CommandInterface $command) |
|
110 | } |
||
111 |
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: