Failed Conditions
Pull Request — master (#82)
by Maximo
05:38
created

TokenBase::isValidCheck()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 3.072
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Middleware;
6
7
use Gewaer\Http\Request;
8
use Phalcon\Http\RequestInterface;
9
use Gewaer\Traits\TokenTrait;
10
use Phalcon\Mvc\Micro\MiddlewareInterface;
11
use Gewaer\Exception\UnauthorizedHttpException;
12
use Phalcon\Mvc\Micro;
13
14
/**
15
 * Class AuthenticationMiddleware.
16
 *
17
 * @package Niden\Middleware
18
 */
19
abstract class TokenBase implements MiddlewareInterface
20
{
21
    use TokenTrait;
22
23
    /**
24
     * @param Request $request
25
     *
26
     * @return bool
27
     */
28 69
    protected function isValidCheck(RequestInterface $request, Micro $app): bool
29
    {
30 69
        $ignoreJwt = $request->ignoreJwt($app['router']->getMatchedRoute());
1 ignored issue
show
Bug introduced by
The method ignoreJwt() does not exist on Phalcon\Http\RequestInterface. It seems like you code against a sub-type of Phalcon\Http\RequestInterface such as Gewaer\Http\Request. ( Ignorable by Annotation )

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

30
        /** @scrutinizer ignore-call */ 
31
        $ignoreJwt = $request->ignoreJwt($app['router']->getMatchedRoute());
Loading history...
31 69
        if (!$ignoreJwt && $request->isEmptyBearerToken()) {
1 ignored issue
show
Bug introduced by
The method isEmptyBearerToken() does not exist on Phalcon\Http\RequestInterface. It seems like you code against a sub-type of Phalcon\Http\RequestInterface such as Gewaer\Http\Request. ( Ignorable by Annotation )

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

31
        if (!$ignoreJwt && $request->/** @scrutinizer ignore-call */ isEmptyBearerToken()) {
Loading history...
32
            throw new UnauthorizedHttpException('Missing Token');
33
        }
34
35 69
        return !$ignoreJwt;
36
    }
37
}
38