1 | <?php |
||
14 | class GuardCoverageToolHandler implements CommandHandlerInterface |
||
15 | { |
||
16 | const CHECKING_MESSAGE = 'Checking your current coverage'; |
||
17 | /** |
||
18 | * @var OutputInterface |
||
19 | */ |
||
20 | private $output; |
||
21 | /** |
||
22 | * @var StrictCoverageProcessorInterface |
||
23 | */ |
||
24 | private $strictCoverageProcessor; |
||
25 | /** |
||
26 | * @var GuardCoverageFileReaderInterface |
||
27 | */ |
||
28 | private $guardReader; |
||
29 | /** |
||
30 | * @var GuardCoverageFileWriterInterface |
||
31 | */ |
||
32 | private $guardWriter; |
||
33 | /** |
||
34 | * @var float; |
||
35 | */ |
||
36 | private $currentCoverage; |
||
37 | /** |
||
38 | * @var float |
||
39 | */ |
||
40 | private $previousCoverage; |
||
41 | |||
42 | /** |
||
43 | * GuardCoverageTool constructor. |
||
44 | * |
||
45 | * @param OutputInterface $output |
||
46 | * @param StrictCoverageProcessorInterface $strictCoverageProcessor |
||
47 | * @param GuardCoverageFileReaderInterface $guardReader |
||
48 | * @param GuardCoverageFileWriterInterface $guardWriter |
||
49 | */ |
||
50 | 2 | public function __construct( |
|
61 | |||
62 | /** |
||
63 | * @param string $warningMessage |
||
64 | */ |
||
65 | 2 | private function run($warningMessage) |
|
87 | |||
88 | /** |
||
89 | * @return bool |
||
90 | */ |
||
91 | 2 | private function isLowerCurrentCoverage() |
|
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | */ |
||
99 | 1 | private function printGuardCoverage() |
|
107 | |||
108 | /** |
||
109 | * @param CommandInterface|GuardCoverage $command |
||
110 | */ |
||
111 | 2 | public function handle(CommandInterface $command) |
|
115 | } |
||
116 |
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: