1 | <?php |
||
18 | class RetryablePackageFailureException extends AbstractException { |
||
19 | /** |
||
20 | * @override \Exception |
||
21 | */ |
||
22 | public function __construct(Throwable $previous) { |
||
26 | |||
27 | /** |
||
28 | * @override \ComponentManager\Exception\AbstractException |
||
29 | */ |
||
30 | public function getExceptionType() { |
||
33 | |||
34 | /** |
||
35 | * @override \ComponentManager\Exception\AbstractException |
||
36 | */ |
||
37 | public function getExceptionCodeName() { |
||
40 | } |
||
41 |
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: