| Conditions | 5 |
| Paths | 3 |
| Total Lines | 10 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 5.1158 |
| Changes | 0 | ||
| 1 | <?php namespace Arcanedev\LaravelTracker\Trackers; |
||
| 47 | 10 | public function getCode(Exception $exception) |
|
| 48 | { |
||
| 49 | 10 | if (method_exists($exception, 'getCode') && $code = $exception->getCode()) |
|
| 50 | 8 | return $code; |
|
| 51 | |||
| 52 | 4 | if (method_exists($exception, 'getStatusCode') && $code = $exception->getStatusCode()) |
|
|
|
|||
| 53 | 4 | return $code; |
|
| 54 | |||
| 55 | return null; |
||
| 56 | } |
||
| 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: