1 | <?php |
||
14 | class MigrateController extends AbstractActionController |
||
15 | { |
||
16 | /** |
||
17 | * @var Migration |
||
18 | */ |
||
19 | protected $migration; |
||
20 | |||
21 | /** |
||
22 | * @var Generator |
||
23 | */ |
||
24 | protected $generator; |
||
25 | |||
26 | public function onDispatch(MvcEvent $e) |
||
34 | /** |
||
35 | * MigrateController constructor. |
||
36 | * |
||
37 | * @param Migration $migration |
||
38 | * @param Generator $generator |
||
39 | */ |
||
40 | public function __construct(Migration $migration, Generator $generator) |
||
45 | |||
46 | /** |
||
47 | * Apply migration |
||
48 | */ |
||
49 | public function applyAction() |
||
66 | |||
67 | /** |
||
68 | * Generate new migration skeleton class |
||
69 | */ |
||
70 | public function generateAction() |
||
76 | |||
77 | /** |
||
78 | * @return Migration |
||
79 | */ |
||
80 | public function getMigration() |
||
84 | |||
85 | /** |
||
86 | * @return Generator |
||
87 | */ |
||
88 | public function getGenerator() |
||
92 | } |
||
93 |
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: