Conditions | 4 |
Paths | 4 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
13 | function map($name) |
||
14 | { |
||
15 | foreach ($this->getModules() as $module) { |
||
16 | if ($module['name'] == $name) { |
||
17 | try { |
||
18 | $this->getKernel()->module($name); |
||
19 | } catch (Exception $e) { |
||
20 | throw new Exception('No access to module ' . $name . ': ' . $e->getMessage()); |
||
21 | } |
||
22 | return 'Intraface_modules_'.$name.'_Controller_Index'; |
||
23 | } |
||
24 | } |
||
25 | return parent::map($name); |
||
26 | } |
||
27 | |||
56 |
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: