1 | <?php |
||||||
2 | |||||||
3 | namespace Gameap\Http\Requests; |
||||||
4 | |||||||
5 | use Gameap\Exceptions\ValidationException; |
||||||
6 | use Illuminate\Contracts\Validation\Validator; |
||||||
7 | use Illuminate\Http\Response; |
||||||
8 | use Illuminate\Validation\Factory; |
||||||
9 | |||||||
10 | abstract class JsonRequest extends Request |
||||||
11 | { |
||||||
12 | /** |
||||||
13 | * Determine if the user is authorized to make this request. |
||||||
14 | * |
||||||
15 | * @return bool |
||||||
16 | */ |
||||||
17 | public function authorize() |
||||||
18 | { |
||||||
19 | return true; |
||||||
20 | } |
||||||
21 | |||||||
22 | /** |
||||||
23 | * Handle a failed validation attempt. |
||||||
24 | * |
||||||
25 | * @param \Illuminate\Contracts\Validation\Validator $validator |
||||||
26 | * @return void |
||||||
27 | * |
||||||
28 | * @throws \Illuminate\Validation\ValidationException |
||||||
29 | */ |
||||||
30 | public function failedValidation(Validator $validator): void |
||||||
31 | { |
||||||
32 | throw new ValidationException(implode(', ', $validator->errors()->all()), Response::HTTP_UNPROCESSABLE_ENTITY); |
||||||
33 | } |
||||||
34 | |||||||
35 | /** |
||||||
36 | * Get the validator instance for the request. |
||||||
37 | * |
||||||
38 | * @return \Illuminate\Validation\Validator |
||||||
39 | */ |
||||||
40 | protected function getValidatorInstance() |
||||||
41 | { |
||||||
42 | /** @var Factory $factory */ |
||||||
43 | $factory = $this->container->make(Factory::class); |
||||||
44 | |||||||
45 | if (method_exists($this, 'validator')) { |
||||||
46 | return $this->container->call([$this, 'validator'], compact('factory')); |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
47 | } |
||||||
48 | |||||||
49 | $data = $this->json->all(); |
||||||
0 ignored issues
–
show
The method
all() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
50 | |||||||
51 | if (empty($data)) { |
||||||
52 | $data = $this->request->all(); |
||||||
53 | } |
||||||
54 | |||||||
55 | return $factory->make( |
||||||
56 | $data, |
||||||
57 | $this->container->call([$this, 'rules']), |
||||||
0 ignored issues
–
show
It seems like
$this->container->call(array($this, 'rules')) can also be of type callable ; however, parameter $rules of Illuminate\Validation\Factory::make() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
58 | $this->messages(), |
||||||
59 | $this->attributes() |
||||||
60 | ); |
||||||
61 | } |
||||||
62 | } |
||||||
63 |