PhoneVerificationRequest::authorize()   B
last analyzed

Complexity

Conditions 9
Paths 5

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.0555
c 0
b 0
f 0
cc 9
nc 5
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Tenantarea;
6
7
use Illuminate\Foundation\Http\FormRequest;
8
use Cortex\Foundation\Exceptions\GenericException;
9
10
class PhoneVerificationRequest 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
        $user = $this->user($this->route('guard'))
22
                ?? $this->attemptUser($this->route('guard'))
0 ignored issues
show
Documentation Bug introduced by
The method attemptUser does not exist on object<Cortex\Auth\Http\...oneVerificationRequest>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
23
                   ?? app('cortex.auth.member')->whereNotNull('phone')->where('phone', $this->get('phone'))->first();
24
25
        // Redirect users if their phone already verified, no need to process their request
26
        if ($user && $user->hasVerifiedPhone()) {
27
            throw new GenericException(trans('cortex/auth::messages.verification.phone.already_verified'), route('tenantarea.account.settings'));
0 ignored issues
show
Documentation introduced by
route('tenantarea.account.settings') 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...
28
        }
29
30
        // Phone field required before verification
31
        if ($user && ! $user->phone) {
32
            throw new GenericException(trans('cortex/auth::messages.account.phone_required'), route('tenantarea.account.settings'));
0 ignored issues
show
Documentation introduced by
route('tenantarea.account.settings') 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...
33
        }
34
35
        // Country field required for phone verification
36
        if ($user && ! $user->country_code) {
37
            throw new GenericException(trans('cortex/auth::messages.account.country_required'), route('tenantarea.account.settings'));
0 ignored issues
show
Documentation introduced by
route('tenantarea.account.settings') 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...
38
        }
39
40
        // Email verification required for phone verification
41
        if ($user && ! $user->hasVerifiedPhone()) {
42
            throw new GenericException(trans('cortex/auth::messages.account.email_verification_required'), route('tenantarea.verification.email.request'));
0 ignored issues
show
Documentation introduced by
route('tenantarea.verification.email.request') 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...
43
        }
44
45
        return true;
46
    }
47
48
    /**
49
     * Get the validation rules that apply to the request.
50
     *
51
     * @return array
52
     */
53
    public function rules(): array
54
    {
55
        return [];
56
    }
57
}
58