Failed Conditions
Pull Request — master (#10)
by Maximo
03:08
created

TokenValidationMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 22
ccs 6
cts 6
cp 1
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
use Phalcon\Http\Request;
11
use Exception;
12
13
/**
14
 * Class TokenValidationMiddleware
15
 *
16
 * @package Gewaer\Middleware
17
 */
18
class TokenValidationMiddleware implements MiddlewareInterface
19
{
20
    /**
21
     * @param Micro $api
22
     *
23
     * @return bool
24
     * @throws ModelException
25
     */
26 2
    public function call(Micro $api)
27
    {
28 2
        $config = $api->getService('config');
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
29
30 2
        $auth = $api->getService('auth');
31
        // to get the payload
32 2
        $data = $auth->data();
33
34 2
        if (!empty($data) && $data['iat'] <= strtotime('-10 seconds')) {
35
            // return false to invalidate the authentication
36
            //throw new Exception("Old Request");
37
        }
38
39 2
        return true;
40
    }
41
}
42