Code Duplication    Length = 37-40 lines in 2 locations

src/Requests/PermissionRequest.php 1 location

@@ 17-56 (lines=40) @@
14
 * @license  https://github.com/mamikon/role-manager/blob/master/LICENSE.md MIT
15
 * @link     https://github.com/mamikon/role-manager
16
 */
17
class PermissionRequest extends FormRequest
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

src/Requests/RoleRequest.php 1 location

@@ 18-54 (lines=37) @@
15
 * @license  https://github.com/mamikon/role-manager/blob/master/LICENSE.md MIT
16
 * @link     https://github.com/mamikon/role-manager
17
 */
18
class RoleRequest extends FormRequest
19
{
20
    /**
21
     * Determine if the user is authorized to make this request.
22
     *
23
     * @return bool
24
     */
25
    public function authorize()
26
    {
27
        return true;
28
    }
29
30
    /**
31
     * Get the validation rules that apply to the request.
32
     *
33
     * @return array
34
     */
35
    public function rules()
36
    {
37
        $return = [
38
            'description' => 'required|max:255',
39
            'name' => 'required|max:255|unique:' .
40
                config('roleManager.rolesTable') . ',name',
41
            'permission.*' => 'exists:' .
42
                config('roleManager.permissionsTable') . ',id'
43
44
        ];
45
46
        if (Request::isMethod('put')) {
47
            $role = Roles::where('id', Request::route('role'))->firstOrFail();
48
            if ($role->name == Request::input('name')) {
49
                $return['name'] = 'required|max:255';
50
            }
51
        }
52
        return $return;
53
    }
54
}
55