1 | <?php declare(strict_types=1); |
||
13 | class IfGenerator extends AbstractGenerator |
||
14 | { |
||
15 | use CodeTrait; |
||
16 | |||
17 | /** @var bool Flag that condition is first */ |
||
18 | protected $isFirstCondition = true; |
||
19 | |||
20 | /** |
||
21 | * @inheritdoc |
||
22 | */ |
||
23 | public function defCondition(string $definition = ''): ConditionGenerator |
||
35 | |||
36 | /** |
||
37 | * @inheritdoc |
||
38 | */ |
||
39 | public function code(): string |
||
60 | } |
||
61 |
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 sub-classes 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 parent class: