Completed
Push — develop ( fdfb11...a4a128 )
by Abdelrahman
01:55
created

AbilityFormRequest::authorize()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Adminarea;
6
7
use Rinvex\Support\Traits\Escaper;
8
use Illuminate\Foundation\Http\FormRequest;
9
use Cortex\Foundation\Exceptions\GenericException;
10
11
class AbilityFormRequest extends FormRequest
12
{
13
    use Escaper;
14
15
    /**
16
     * Determine if the user is authorized to make this request.
17
     *
18
     * @throws \Cortex\Foundation\Exceptions\GenericException
19
     *
20
     * @return bool
21
     */
22
    public function authorize(): bool
23
    {
24
        $currentUser = $this->user($this->route('guard'));
25
26
        if (optional($this->route('ability'))->exists && ! $currentUser->can('superadmin') && ! $currentUser->getAbilities()->contains($this->route('ability'))) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 162 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...
27
            throw new GenericException(trans('cortex/auth::messages.action_unauthorized'), route('adminarea.abilities.index'));
0 ignored issues
show
Documentation introduced by
route('adminarea.abilities.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 127 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...
28
        }
29
30
        return true;
31
    }
32
33
    /**
34
     * Configure the validator instance.
35
     *
36
     * @param \Illuminate\Validation\Validator $validator
37
     *
38
     * @return void
39
     */
40
    public function withValidator($validator): void
41
    {
42
        // Sanitize input data before submission
43
        $this->replace($this->escape($this->all()));
44
    }
45
46
    /**
47
     * Get the validation rules that apply to the request.
48
     *
49
     * @return array
50
     */
51
    public function rules(): array
52
    {
53
        return [];
54
    }
55
}
56