| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace Tarsana\Command\Helpers; |
||
| 25 | public function asString(Syntax $syntax) : string |
||
| 26 | { |
||
| 27 | $type = $this->type($syntax); |
||
| 28 | if ($type == 'optional') |
||
| 29 | return $this->asString($syntax->syntax()); |
||
|
|
|||
| 30 | switch ($type) { |
||
| 31 | case 'object': |
||
| 32 | return implode( |
||
| 33 | $syntax->separator(), |
||
| 34 | array_keys($syntax->fields()) |
||
| 35 | ); |
||
| 36 | break; |
||
| 37 | case 'array': |
||
| 38 | $text = $this->asString($syntax->syntax()); |
||
| 39 | return "{$text}{$syntax->separator()}..."; |
||
| 40 | break; |
||
| 41 | default: |
||
| 42 | return $type; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 60 |
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: