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

TokenValidationMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 29
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 21 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Middleware;
6
7
use Gewaer\Exception\ModelException;
8
use Phalcon\Mvc\Micro;
9
use Phalcon\Http\Request;
10
use Gewaer\Models\Users;
11
use Gewaer\Exception\PermissionException;
12
13
/**
14
 * Class TokenValidationMiddleware.
15
 *
16
 * @package Gewaer\Middleware
17
 */
18
class TokenValidationMiddleware extends TokenBase
19
{
20
    /**
21
     * @param Micro $api
22
     *
23
     * @return bool
24
     * @throws ModelException
25
     */
26 69
    public function call(Micro $api)
27
    {
28
        /** @var Request $request */
29 69
        $request = $api->getService('request');
30
31 69
        if ($this->isValidCheck($request)) {
32
            /**
33
             * This is where we will validate the token that was sent to us
34
             * using Bearer Authentication.
35
             *
36
             * Find the user attached to this token
37
             */
38 65
            $token = $this->getToken($request->getBearerTokenFromHeader());
39
40 65
            if (!$token->validate(Users::getValidationData($token->getHeader('jti')))) {
41
                throw new PermissionException('Invalid Token');
42
                //return false;
43
            }
44
        }
45
46 68
        return true;
47
    }
48
}
49