EnsureMobileIsVerified::handle()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 11
rs 9.6111
cc 5
nc 3
nop 3
1
<?php
2
3
namespace Fouladgar\MobileVerification\Http\Middleware;
4
5
use Closure;
6
use Fouladgar\MobileVerification\Contracts\MustVerifyMobile;
7
8
class EnsureMobileIsVerified
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param $request
14
     * @param Closure $next
15
     * @param null    $redirectToRoute
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $redirectToRoute is correct as it would always require null to be passed?
Loading history...
16
     *
17
     * @return mixed|void
18
     */
19
    public function handle($request, Closure $next, $redirectToRoute = null)
0 ignored issues
show
Unused Code introduced by
The parameter $redirectToRoute is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

19
    public function handle($request, Closure $next, /** @scrutinizer ignore-unused */ $redirectToRoute = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        $user = auth()->user();
22
23
        if (! $user || ($user instanceof MustVerifyMobile && ! $user->hasVerifiedMobile())) {
24
            return $request->expectsJson()
25
                ? abort(403, 'Your mobile number is not verified.')
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort(403, 'Your mobile number is not verified.') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
26
                : redirect('/')->withErrors(['mobile' => 'Your mobile number is not verified.']);
27
        }
28
29
        return $next($request);
30
    }
31
}
32