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

RequestJwtTrait::ignoreJwt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Traits;
6
7
use Baka\Http\RouterCollection;
8
use Phalcon\Mvc\Router\Route;
9
10
/**
11
 * Trait TokenTrait.
12
 *
13
 * @package Niden\Traits
14
 */
15
trait RequestJwtTrait
16
{
17
    /**
18
    * @return string
19
    */
20 61
    public function getBearerTokenFromHeader(): string
21
    {
22 61
        return str_replace('Bearer ', '', $this->getHeader('Authorization'));
0 ignored issues
show
Bug introduced by
It seems like getHeader() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

22
        return str_replace('Bearer ', '', $this->/** @scrutinizer ignore-call */ getHeader('Authorization'));
Loading history...
23
    }
24
25
    /**
26
     * @return bool
27
     */
28 61
    public function isEmptyBearerToken(): bool
29
    {
30 61
        return empty($this->getBearerTokenFromHeader());
31
    }
32
33
    /**
34
     * Did we specify we dont need to validate JWT Token on this section?
35
     *
36
     * @return bool
37
     */
38 69
    public function ignoreJwt(Route $route) : bool
39
    {
40
        //did we find the router?
41 69
        if (is_array(RouterCollection::getJwtIgnoreRoutes()[$route->getHttpMethods()])) {
42 69
            return isset(RouterCollection::getJwtIgnoreRoutes()[$route->getHttpMethods()][md5($route->getPattern())]);
43
        }
44
45
        //nop we dont have this route in ignore jwt
46 22
        return false;
47
    }
48
}
49