1 | <?php |
||
17 | class Module implements ConsoleUsage, Config, Autoloader, BootstrapListener |
||
18 | { |
||
19 | |||
20 | const CONSOLE_GEOIP_DOWNLOAD = 'geoip download [--no-clobber] [-q]'; |
||
21 | |||
22 | /** |
||
23 | * @return array |
||
24 | */ |
||
25 | public function getConfig() |
||
26 | { |
||
27 | return include __DIR__ . '/../../config/module.config.php'; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return array |
||
32 | */ |
||
33 | public function getAutoloaderConfig() |
||
34 | { |
||
35 | return [ |
||
36 | 'Zend\Loader\StandardAutoloader' => [ |
||
37 | 'namespaces' => [ |
||
38 | __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, |
||
39 | ], |
||
40 | ], |
||
41 | ]; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param AdapterInterface $console |
||
46 | * @return array |
||
47 | * |
||
48 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
49 | */ |
||
50 | public function getConsoleUsage(AdapterInterface $console) |
||
51 | { |
||
52 | return ['Manage GeoIP database', |
||
53 | self::CONSOLE_GEOIP_DOWNLOAD => 'Downloads the newest GeoIP db', |
||
54 | ['--no-clobber', 'Don\'t overwrite an existing db file'], |
||
55 | ['-q', 'Turn off output'], |
||
56 | ]; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param \Zend\Mvc\MvcEvent $event |
||
61 | */ |
||
62 | public function onBootstrap(EventInterface $event) |
||
69 | } |
||
70 |
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: