Completed
Push — develop ( 508664...7b00fe )
by Abdelrahman
01:58
created

RoleFormRequest::prepareForValidation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A RoleFormRequest::rules() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Adminarea;
6
7
use Illuminate\Foundation\Http\FormRequest;
8
use Cortex\Foundation\Exceptions\GenericException;
9
10
class RoleFormRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @throws \Cortex\Foundation\Exceptions\GenericException
16
     *
17
     * @return bool
18
     */
19
    public function authorize(): bool
20
    {
21
        $currentUser = $this->user($this->route('guard'));
22
23
        if (optional($this->route('role'))->exists && ! $currentUser->can('superadmin') && ! $currentUser->roles->contains($this->route('role'))) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 147 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
24
            throw new GenericException(trans('cortex/auth::messages.action_unauthorized'), route('adminarea.roles.index'));
0 ignored issues
show
Documentation introduced by
route('adminarea.roles.index') is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
25
        }
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(): array
36
    {
37
        return [];
38
    }
39
}
40