RequestJwtTrait::isEmptyBearerToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Traits;
6
7
use Baka\Http\Router\Collection;
0 ignored issues
show
Bug introduced by
The type Baka\Http\Router\Collection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Phalcon\Mvc\Router\Route;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\Router\Route was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Trait TokenTrait.
12
 *
13
 * @package Niden\Traits
14
 */
15
trait RequestJwtTrait
16
{
17
    /**
18
    * @return string
19
    */
20
    public function getBearerTokenFromHeader(): string
21
    {
22
        return str_replace('Bearer ', '', $this->getHeader('Authorization'));
23
    }
24
25
    /**
26
     * @return bool
27
     */
28
    public function isEmptyBearerToken(): bool
29
    {
30
        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
    public function ignoreJwt(Route $route) : bool
39
    {
40
        //did we find the router?
41
        if (is_array(Collection::getJwtIgnoreRoutes()[$route->getHttpMethods()])) {
42
            return isset(Collection::getJwtIgnoreRoutes()[$route->getHttpMethods()][md5($route->getPattern())]);
43
        }
44
45
        //nop we dont have this route in ignore jwt
46
        return false;
47
    }
48
49
    abstract public function getHeader($header);
50
}
51