| 1 | <?php |
||
| 12 | class OptionalParamBeforeRequired implements Pass\AnalyzerPassInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @param Stmt $func |
||
| 16 | * @param Context $context |
||
| 17 | * @return bool |
||
| 18 | */ |
||
| 19 | public function pass(Stmt $func, Context $context) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return array |
||
| 35 | */ |
||
| 36 | public function getRegister() |
||
| 43 | } |
||
| 44 |
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: