ServiceAbstractBase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decodePreviousToken() 0 8 2
A createToken() 0 5 1
1
<?php
2
/**
3
 * User: jg
4
 * Date: 30/09/17
5
 * Time: 18:10
6
 */
7
8
namespace RestTemplate\Rest;
9
10
use ByJG\RestServer\Exception\Error401Exception;
11
use ByJG\RestServer\ServiceAbstract;
12
use ByJG\Util\JwtWrapper;
13
use RestTemplate\Psr11;
14
15
class ServiceAbstractBase extends ServiceAbstract
16
{
17
18
    /**
19
     * @param array $properties
20
     * @return mixed
21
     */
22
    public function createToken($properties = [])
23
    {
24
        $jwt = new JwtWrapper(Psr11::container()->get('JWT_SERVER'), Psr11::container()->get('JWT_SECRET'));
25
        $jwtData = $jwt->createJwtData($properties, 1800);
26
        return $jwt->generateToken($jwtData);
27
    }
28
29
    public function decodePreviousToken($token = null)
30
    {
31
        try {
32
            $jwt = new JwtWrapper(Psr11::container()->get('JWT_SERVER'), Psr11::container()->get('JWT_SECRET'));
33
            $tokenInfo = json_decode(json_encode($jwt->extractData($token)), true);
34
            return $tokenInfo['data'];
35
        } catch (\Exception $ex) {
36
            throw new Error401Exception($ex->getMessage());
37
        }
38
    }
39
}
40