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 | * List migrations - not applied by default, all with 'all' flag. |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | public function listAction() |
||
60 | |||
61 | /** |
||
62 | * Apply migration |
||
63 | */ |
||
64 | public function applyAction() |
||
81 | |||
82 | /** |
||
83 | * Generate new migration skeleton class |
||
84 | */ |
||
85 | public function generateAction() |
||
91 | |||
92 | /** |
||
93 | * @return Migration |
||
94 | */ |
||
95 | public function getMigration() |
||
99 | |||
100 | /** |
||
101 | * @return Generator |
||
102 | */ |
||
103 | public function getGenerator() |
||
107 | } |
||
108 |
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: