| Conditions | 2 |
| Paths | 2 |
| Total Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function fromErrors(array $errors) |
||
| 16 | { |
||
| 17 | $result = []; |
||
| 18 | |||
| 19 | foreach ($errors as $error) { |
||
| 20 | $result[] = collect( |
||
| 21 | [ |
||
| 22 | 'idx' => $error->getId(), |
||
| 23 | 'links' => $error->getLinks(), |
||
| 24 | 'status' => $error->getStatus(), |
||
| 25 | 'code' => $error->getCode(), |
||
| 26 | 'title' => $error->getTitle(), |
||
| 27 | 'detail' => $error->getDetail(), |
||
| 28 | 'source' => $error->getSource(), |
||
| 29 | 'meta' => $error->getMeta() |
||
| 30 | ] |
||
| 31 | )->reject( |
||
| 32 | function ($item) |
||
| 33 | { |
||
| 34 | return is_null($item); |
||
| 35 | } |
||
| 36 | )->toArray(); |
||
| 37 | } |
||
| 38 | |||
| 39 | return response()->json( |
||
|
|
|||
| 40 | [ |
||
| 41 | 'errors' => $result |
||
| 42 | ], |
||
| 43 | 422 |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: