Test Failed
Push — master ( e7e248...cb9afd )
by Maximo
02:40 queued 40s
created

TokenValidationMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 14 3
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
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\Mvc\Micro\MiddlewareInterface;
10
11
/**
12
 * Class TokenValidationMiddleware
13
 *
14
 * @package Gewaer\Middleware
15
 */
16
class TokenValidationMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @param Micro $api
20
     *
21
     * @return bool
22
     * @throws ModelException
23
     */
24
    public function call(Micro $api)
25
    {
26
        $config = $api->getService('config');
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
27
28
        $auth = $api->getService('auth');
29
        // to get the payload
30
        $data = $auth->data();
31
32
        if (!empty($data) && $data['iat'] <= strtotime('-10 seconds')) {
33
            // return false to invalidate the authentication
34
            //throw new Exception("Old Request");
35
        }
36
37
        return true;
38
    }
39
}
40