Passed
Push — master ( 3f2443...09679e )
by Maximo
03:08
created

RequestJwtTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBearerTokenFromHeader() 0 3 1
A isEmptyBearerToken() 0 3 1
A ignoreJwt() 0 9 2
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'));
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
    abstract public function getHeader($header);
50
}
51