Conditions | 4 |
Paths | 4 |
Total Lines | 12 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php namespace Tarsana\Command\Helpers; |
||
46 | public function fields(Syntax $syntax) : array |
||
47 | { |
||
48 | $type = $this->type($syntax); |
||
49 | switch ($type) { |
||
50 | case 'object': |
||
51 | return $syntax->fields(); |
||
52 | case 'array': |
||
53 | case 'optional': |
||
54 | return $this->fields($syntax->syntax()); |
||
55 | } |
||
56 | return []; |
||
57 | } |
||
58 | |||
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: