Completed
Push — master ( a77c04...464b27 )
by Andrey
16:47
created

UpdatePermission::messages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 View Code Duplication
    public function rules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
Unused Code introduced by
The call to Unique::where() has too many arguments starting with $id.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43
            ],
44
            'description' => [
45
                'required',
46
                'string',
47
                'min:3',
48
                'max:191',
49
                Rule::unique('permissions')->where('id', '<>', $id),
0 ignored issues
show
Unused Code introduced by
The call to Unique::where() has too many arguments starting with $id.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
50
            ],
51
        ];
52
    }
53
54
    /**
55
     * Get the error messages for the defined validation rules.
56
     *
57
     * @return array
58
     */
59 View Code Duplication
    public function messages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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