Test Failed
Pull Request — master (#80)
by Maximo
05:46
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 Gewaer\Traits\TokenTrait;
9
use Phalcon\Mvc\Micro\MiddlewareInterface;
10
use Gewaer\Exception\UnauthorizedHttpException;
11
use Phalcon\Mvc\Micro;
12
13
/**
14
 * Class AuthenticationMiddleware.
15
 *
16
 * @package Niden\Middleware
17
 */
18
abstract class TokenBase implements MiddlewareInterface
19
{
20
    use TokenTrait;
21
22
    /**
23
     * @param Request $request
24
     *
25
     * @return bool
26
     */
27 69
    protected function isValidCheck(Request $request, Micro $app): bool
28
    {
29 69
        $ignoreJwt = $request->ignoreJwt($app['router']->getMatchedRoute());
30 69
        if (!$ignoreJwt && $request->isEmptyBearerToken()) {
31 69
            throw new UnauthorizedHttpException('Missing Token');
32
        }
33
34
        return !$ignoreJwt;
35
    }
36
}
37