| 1 | <?php namespace Arcanedev\LaravelTracker\Trackers; |
||
| 13 | class ErrorTracker extends AbstractTracker implements ErrorTrackerContract |
||
| 14 | { |
||
| 15 | /* ------------------------------------------------------------------------------------------------ |
||
| 16 | | Main Functions |
||
| 17 | | ------------------------------------------------------------------------------------------------ |
||
| 18 | */ |
||
| 19 | /** |
||
| 20 | * Track the exception error. |
||
| 21 | * |
||
| 22 | * @param \Exception $exception |
||
| 23 | * |
||
| 24 | * @return int |
||
| 25 | */ |
||
| 26 | 10 | public function track(Exception $exception) |
|
| 35 | |||
| 36 | /* ------------------------------------------------------------------------------------------------ |
||
| 37 | | Other Functions |
||
| 38 | | ------------------------------------------------------------------------------------------------ |
||
| 39 | */ |
||
| 40 | /** |
||
| 41 | * Get the code from the exception. |
||
| 42 | * |
||
| 43 | * @param \Exception $exception |
||
| 44 | * |
||
| 45 | * @return int|mixed|null |
||
| 46 | */ |
||
| 47 | 10 | public function getCode(Exception $exception) |
|
| 57 | } |
||
| 58 |
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: