1 | <?php |
||
10 | trait ValidatesRequests |
||
11 | { |
||
12 | /** @var ErrorCollection */ |
||
13 | protected $errors; |
||
14 | |||
15 | /** @var Factory */ |
||
16 | protected $validatorFactory; |
||
17 | |||
18 | public function isValid(Request $request) : bool |
||
19 | { |
||
20 | $this->errors = new ErrorCollection(); |
||
21 | |||
22 | /** @var \Illuminate\Contracts\Validation\Validator $validator */ |
||
23 | $validator = $this->validatorFactory->make($request->json(), $this->rules(), $this->messages()); |
||
24 | if ($validator->fails()) { |
||
25 | // @todo put this somewhere else, this is getting messy |
||
26 | // @see https://jsonapi.org/examples/#error-objects-basic |
||
27 | foreach ($validator->errors()->all() as $field => $errorMessage) { |
||
|
|||
28 | |||
29 | // get the pointer for an array so we can pinpoint the section |
||
30 | // of json where the error occurred |
||
31 | $field = '/'.str_replace('.', '/', $field).'/'; |
||
32 | |||
33 | $this->errors->add(new Error( |
||
34 | null, |
||
35 | null, |
||
36 | 422, |
||
37 | null, |
||
38 | 'Invalid Attribute', |
||
39 | $errorMessage, |
||
40 | [ |
||
41 | 'pointer' => $field, |
||
42 | ] |
||
43 | )); |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | |||
48 | public function rules(array $rules = null) : array |
||
57 | |||
58 | public function messages(array $messages = null) : array |
||
68 | |||
69 | public function errors() : ErrorCollection |
||
73 | |||
74 | /** |
||
75 | * The type of entity this request is for. |
||
76 | */ |
||
77 | abstract public function type() : string; |
||
78 | |||
79 | public function setValidatorFactory(Factory $factory) |
||
83 | } |
||
84 |
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.