Jwt::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Service;
4
5
use \Firebase\JWT\JWT as JsonWebToken;
6
7
class Jwt
8
{
9
	/**
10
     * encode an array in jwt
11
	 * @param array $values
12
	 * @param string $token
13
	 * @return string
14
	 */
15
	public static function encode(array $values, string $token)
16
	{
17
		return JsonWebToken::encode($values, $token);
18
	}
19
	
20
	/**
21
     * encode a jwt in array
22
	 * @param string $encoded_json
23
	 * @param string $token
24
	 * @return bool|object
25
	 */
26
	public static function decode(string $encoded_json, string $token)
27
	{
28
		JsonWebToken::$leeway = 5;
29
		$decoded = JsonWebToken::decode($encoded_json, $token, ['HS256']);
30
		
31
		if ($decoded) {
0 ignored issues
show
introduced by
$decoded is of type object, thus it always evaluated to true.
Loading history...
32
			return $decoded;
33
		}
34
		
35
		return false;
36
	}
37
}
38