Test Failed
Pull Request — master (#80)
by Maximo
05:46
created

Request   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 31
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBearerTokenFromHeader() 0 3 1
A ignoreJwt() 0 8 2
A isEmptyBearerToken() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Http;
6
7
use Phalcon\Http\Request as PhRequest;
8
use Baka\Http\RouterCollection;
9
use Phalcon\Mvc\Router\Route;
10
11
class Request extends PhRequest
12
{
13
    /**
14
    * @return string
15
    */
16 69
    public function getBearerTokenFromHeader(): string
17
    {
18 69
        return str_replace('Bearer ', '', $this->getHeader('Authorization'));
19
    }
20
21
    /**
22
     * @return bool
23
     */
24 69
    public function isEmptyBearerToken(): bool
25
    {
26 69
        return true === empty($this->getBearerTokenFromHeader());
27
    }
28
29
    /**
30
     * Did we specify we dont need to validate JWT Token on this section?
31
     *
32
     * @return bool
33
     */
34 69
    public function ignoreJwt(Route $route) : bool
35
    {
36
        //did we find the router?
37 69
        if (is_array(RouterCollection::getJwtIgnoreRoutes()[$route->getHttpMethods()])) {
38
            return isset(RouterCollection::getJwtIgnoreRoutes()[$route->getHttpMethods()][md5($route->getPattern())]);
39
        }
40
41 69
        return false;
42
    }
43
}
44