1 | <?php namespace Tarsana\Command\Helpers; |
||
6 | class SyntaxHelper { |
||
7 | |||
8 | protected static $instance; |
||
9 | |||
10 | public static function instance() : SyntaxHelper |
||
16 | |||
17 | private function __construct() {} |
||
18 | |||
19 | public function type(Syntax $syntax) : string |
||
24 | |||
25 | public function asString(Syntax $syntax) : string |
||
45 | |||
46 | public function fields(Syntax $syntax) : array |
||
58 | |||
59 | } |
||
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: