1 | <?php |
||
20 | class ConfigurationProcessorHandler implements CommandHandlerInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var IOInterface |
||
24 | */ |
||
25 | private $io; |
||
26 | /** |
||
27 | * @var PreCommitProcessor |
||
28 | */ |
||
29 | private $preCommitProcessor; |
||
30 | /** |
||
31 | * @var CommitMsgProcessor |
||
32 | */ |
||
33 | private $commitMsgProcessor; |
||
34 | /** |
||
35 | * @var ConfigurationFileWriterInterface |
||
36 | */ |
||
37 | private $configurationFileWriter; |
||
38 | /** |
||
39 | * @var HookCopier |
||
40 | */ |
||
41 | private $hookCopier; |
||
42 | /** |
||
43 | * @var ConfigurationFileReaderInterface |
||
44 | */ |
||
45 | private $configurationFileReader; |
||
46 | /** |
||
47 | * @var PrePushProcessor |
||
48 | */ |
||
49 | private $prePushProcessor; |
||
50 | |||
51 | /** |
||
52 | * ConfigurationProcessor constructor. |
||
53 | * |
||
54 | * @param ConfigurationFileReaderInterface $configurationFileReader |
||
55 | * @param PreCommitProcessor $preCommitProcessor |
||
56 | * @param CommitMsgProcessor $commitMsgProcessor |
||
57 | * @param ConfigurationFileWriterInterface $configurationFileWriter |
||
58 | * @param HookCopier $hookCopier |
||
59 | * @param PrePushProcessor $prePushProcessor |
||
60 | */ |
||
61 | 2 | public function __construct( |
|
76 | |||
77 | /** |
||
78 | * @param IOInterface $input |
||
79 | */ |
||
80 | 2 | private function process(IOInterface $input) |
|
107 | |||
108 | /** |
||
109 | * @param Config $configData |
||
110 | * |
||
111 | * @return PreCommit |
||
112 | */ |
||
113 | 2 | private function preCommitProcess(Config $configData) |
|
120 | |||
121 | /** |
||
122 | * @param Config $configData |
||
123 | * |
||
124 | * @return CommitMsg |
||
125 | */ |
||
126 | 2 | private function commitMsgProcess(Config $configData) |
|
133 | |||
134 | /** |
||
135 | * @param Config $configData |
||
136 | * |
||
137 | * @return PrePush |
||
138 | */ |
||
139 | 2 | private function prePushProcess(Config $configData) |
|
146 | |||
147 | /** |
||
148 | * @param CommandInterface|ConfigurationProcessor $command |
||
149 | */ |
||
150 | 2 | public function handle(CommandInterface $command) |
|
154 | } |
||
155 |
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: