1 | <?php |
||
2 | |||
3 | namespace Itstructure\LaRbac\Http\Requests; |
||
4 | |||
5 | use Illuminate\Foundation\Http\FormRequest; |
||
6 | use Illuminate\Validation\Rule; |
||
7 | |||
8 | /** |
||
9 | * Class UpdatePermission |
||
10 | * |
||
11 | * @package Itstructure\LaRbac\Http\Requests |
||
12 | * |
||
13 | * @author Andrey Girnik <[email protected]> |
||
14 | */ |
||
15 | class UpdatePermission extends FormRequest |
||
16 | { |
||
17 | /** |
||
18 | * Determine if the user is authorized to make this request. |
||
19 | * |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function authorize() |
||
23 | { |
||
24 | return !empty(config('rbac.routesMainPermission')) ? $this->user()->can(config('rbac.routesMainPermission')) : true; |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Get the validation rules that apply to the request. |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | public function rules() |
||
33 | { |
||
34 | $id = $this->route('permission')->id; |
||
35 | return [ |
||
36 | 'name' => [ |
||
37 | 'required', |
||
38 | 'string', |
||
39 | 'regex:/^[\w\s\-]+$/', |
||
40 | 'min:3', |
||
41 | 'max:191', |
||
42 | Rule::unique('permissions')->where('id', '<>', $id), |
||
0 ignored issues
–
show
|
|||
43 | ], |
||
44 | 'description' => [ |
||
45 | 'required', |
||
46 | 'string', |
||
47 | 'min:3', |
||
48 | 'max:191', |
||
49 | Rule::unique('permissions')->where('id', '<>', $id), |
||
50 | ], |
||
51 | ]; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get the error messages for the defined validation rules. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | public function messages() |
||
60 | { |
||
61 | return [ |
||
62 | 'required' => __('rbac::validation.required'), |
||
63 | 'string' => __('rbac::validation.string'), |
||
64 | 'regex' => __('rbac::validation.regex'), |
||
65 | 'min' => __('rbac::validation.min'), |
||
66 | 'max' => __('rbac::validation.max'), |
||
67 | 'unique' => __('rbac::validation.unique'), |
||
68 | ]; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get custom attributes for validator errors. |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | public function attributes() |
||
77 | { |
||
78 | return [ |
||
79 | 'name' => __('rbac::main.name'), |
||
80 | 'description' => __('rbac::main.description'), |
||
81 | ]; |
||
82 | } |
||
83 | } |
||
84 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.