Conditions | 3 |
Paths | 3 |
Total Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | public function __invoke(Request $request) |
||
14 | { |
||
15 | $this->ensureValidSignature($request); |
||
16 | |||
17 | $validator = validator($request->json()->all(), [ |
||
18 | 'batch.*.name' => 'required', |
||
19 | 'batch.*.data' => 'required', |
||
20 | 'batch.*.channel' => 'required', |
||
21 | ], [ |
||
22 | 'required' => 'Missing required parameter: :attribute', |
||
23 | ]); |
||
24 | |||
25 | if ($validator->fails()) { |
||
|
|||
26 | return new JsonResponse([ |
||
27 | 'body' => 'Failed input validation.', |
||
28 | 'status' => 400, |
||
29 | 'validation_errors' => $validator->errors()->toArray(), |
||
30 | ], 400); |
||
31 | } |
||
32 | |||
33 | foreach ($request->json()->get('batch', []) as $event) { |
||
34 | $this->broadcastEventForAppToChannel( |
||
35 | $request->appId, |
||
36 | $event['channel'], |
||
37 | $event['name'], |
||
38 | $event['data'], |
||
39 | $event['socket_id'] ?? null |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | return $request->json()->all(); |
||
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: