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

Request::getBearerTokenFromHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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