Completed
Push — master ( 78de56...a458a2 )
by Abdelrahman
08:50 queued 10s
created

PhoneVerificationProcessRequest::authorize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Frontarea;
6
7
use Cortex\Foundation\Exceptions\GenericException;
8
9
class PhoneVerificationProcessRequest extends PhoneVerificationRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @throws \Cortex\Foundation\Exceptions\GenericException
15
     *
16
     * @return bool
17
     */
18
    public function authorize(): bool
19
    {
20
        parent::authorize();
21
22
        $user = $this->user($this->route('guard'))
23
                ?? $this->attemptUser($this->route('guard'))
0 ignored issues
show
Documentation Bug introduced by
The method attemptUser does not exist on object<Cortex\Auth\Http\...ficationProcessRequest>? 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...
24
                   ?? app('cortex.auth.member')->whereNotNull('phone')->where('phone', $this->get('phone'))->first();
25
26
        if (! $user) {
27
            // User instance required to detect active TwoFactor methods
28
            throw new GenericException(trans('cortex/foundation::messages.session_required'), route('frontarea.login'));
0 ignored issues
show
Documentation introduced by
route('frontarea.login') 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...
29
        }
30
31
        return true;
32
    }
33
34
    /**
35
     * Get the validation rules that apply to the request.
36
     *
37
     * @return array
38
     */
39
    public function rules(): array
40
    {
41
        return [
42
            'token' => 'required|digits_between:6,10',
43
        ];
44
    }
45
}
46