PermissionRequest::rules()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.2
c 0
b 0
f 0
cc 3
eloc 14
nc 3
nop 0
1
<?php
2
3
namespace Mamikon\RoleManager\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Http\Request;
7
use Mamikon\RoleManager\Models\Permissions;
8
/**
9
 * Permission request validation
10
 *
11
 * @category Laravel_Package
12
 * @package  Mamikon\RoleManager
13
 * @author   Mamikon Arakelyan <[email protected]>
14
 * @license  https://github.com/mamikon/role-manager/blob/master/LICENSE.md MIT
15
 * @link     https://github.com/mamikon/role-manager
16
 */
17 View Code Duplication
class PermissionRequest extends FormRequest
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    /**
20
     * Determine if the user is authorized to make this request.
21
     *
22
     * @return bool
23
     */
24
    public function authorize()
25
    {
26
        return true;
27
    }
28
29
    /**
30
     * Get the validation rules that apply to the request.
31
     *
32
     * @return array
33
     */
34
    public function rules()
35
    {
36
        $return = [
37
            'description' => 'required|max:255',
38
            'name' => 'required|max:255|unique:' .
39
                config('roleManager.permissionsTable') . ',name',
40
            'class' => 'classExist',
41
            'method' => 'required_with:class|methodExist'
42
43
        ];
44
45
        if (Request::isMethod('put')) {
46
            $permission = Permissions::where(
47
                'id', Request::route('permission')
48
            )->firstOrFail();
49
            if ($permission->name == Request::input('name')) {
50
                $return['name'] = 'required|max:255';
51
            }
52
53
        }
54
        return $return;
55
    }
56
}
57