1 | <?php |
||
14 | class ChannelChangerFactory |
||
15 | { |
||
16 | protected $config = null; |
||
17 | |||
18 | protected $handlerManager = null; |
||
19 | |||
20 | protected $processManager = null; |
||
21 | |||
22 | protected $formatterManager = null; |
||
23 | |||
24 | 1 | public function __invoke(ContainerInterface $container) |
|
36 | |||
37 | 7 | public function getMainConfig(ContainerInterface $container) |
|
42 | |||
43 | 7 | protected function getConfigArray(ContainerInterface $container) |
|
44 | { |
||
45 | // Symfony config is parameters. // |
||
46 | 7 | if (method_exists($container, 'getParameter') |
|
47 | 7 | && method_exists($container, 'hasParameter') |
|
48 | 7 | && $container->hasParameter('monolog') |
|
1 ignored issue
–
show
|
|||
49 | ) { |
||
50 | 1 | return ['monolog' => $container->getParameter('monolog')]; |
|
1 ignored issue
–
show
|
|||
51 | } |
||
52 | |||
53 | // Zend uses config key |
||
54 | 6 | if ($container->has('config')) { |
|
55 | 5 | return $container->get('config'); |
|
56 | } |
||
57 | |||
58 | // Slim Config comes from "settings" |
||
59 | 1 | if ($container->has('settings')) { |
|
60 | 1 | return ['monolog' => $container->get('settings')['monolog']]; |
|
61 | } |
||
62 | |||
63 | return []; |
||
64 | } |
||
65 | |||
66 | 2 | public function getHandlerManager(ContainerInterface $container) |
|
78 | |||
79 | 3 | public function getFormatterManager(ContainerInterface $container) |
|
90 | |||
91 | 2 | public function getProcessorManager(ContainerInterface $container) |
|
102 | } |
||
103 |
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: