Conditions | 1 |
Paths | 1 |
Total Lines | 4 |
Code Lines | 2 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php namespace nyx\console\input\exceptions; |
||
19 | public function __construct(Arguments $arguments, $message = null, $code = 0, \Exception $previous = null) |
||
20 | { |
||
21 | parent::__construct($arguments, $message ?? 'Not enough arguments given. Got '.$arguments->count().', expected at least '.$arguments->definitions()->required(), $code, $previous); |
||
|
|||
22 | } |
||
23 | } |
||
24 |
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: