| Conditions | 4 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 39 | public function code(): string |
||
| 40 | { |
||
| 41 | // Add child if groups code |
||
| 42 | $code = $this->getNestedCode(self::class); |
||
| 43 | // Add conditions code |
||
| 44 | $code .= $this->getNestedCode(ConditionGenerator::class); |
||
| 45 | |||
| 46 | // Close condition block |
||
| 47 | if ($code !== '') { |
||
| 48 | $code .= "\n" . '}'; |
||
| 49 | } |
||
| 50 | |||
| 51 | // Separate code in lines and add to parent code |
||
| 52 | if ($code !== '') { |
||
| 53 | foreach (explode("\n", $code) as $codeLine) { |
||
| 54 | $this->parent->defLine($codeLine); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return $code; |
||
| 59 | } |
||
| 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: