1 | <?php |
||
13 | class Migration20200827131900 extends AbstractMigration |
||
14 | { |
||
15 | use ModelFactoryTrait; |
||
16 | |||
17 | /** |
||
18 | * @return string |
||
19 | */ |
||
20 | public function description(): string |
||
24 | |||
25 | /** |
||
26 | * Inject dependencies from a DI Container. |
||
27 | * |
||
28 | * @param Container $container A Pimple DI service container. |
||
29 | * @return void |
||
30 | */ |
||
31 | protected function setDependencies(Container $container): void |
||
37 | |||
38 | /** |
||
39 | * Apply migration |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function up(): void |
||
62 | |||
63 | } |
||
64 |
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: