| Conditions | 1 |
| Paths | 1 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | public function logRequest(Request $request) |
||
| 12 | { |
||
| 13 | $method = strtoupper($request->getMethod()); |
||
| 14 | |||
| 15 | $uri = $request->getPathInfo(); |
||
| 16 | |||
| 17 | $bodyAsJson = json_encode($request->except(config('http-logger.except'))); |
||
| 18 | |||
| 19 | $files = array_map(function (UploadedFile $file) { |
||
| 20 | return $file->path(); |
||
|
|
|||
| 21 | }, iterator_to_array($request->files)); |
||
| 22 | |||
| 23 | $message = "{$method} {$uri} - Body: {$bodyAsJson} - Files: ".implode(', ', $files); |
||
| 24 | |||
| 25 | Log::info($message); |
||
| 26 | } |
||
| 27 | } |
||
| 28 |
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: