Passed
Push — master ( 696cbf...968eef )
by Melech
05:53 queued 01:56
created

FirebaseJwt   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 3 1
A __construct() 0 5 1
A decode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Jwt;
15
16
use Firebase\JWT\JWT;
17
use Firebase\JWT\Key;
18
use OpenSSLAsymmetricKey;
19
use OpenSSLCertificate;
20
use Valkyrja\Jwt\Contract\Jwt as Contract;
21
use Valkyrja\Jwt\Enum\Algorithm;
22
23
/**
24
 * Class RsFirebaseJwt.
25
 *
26
 * @author Melech Mizrachi
27
 */
28
class FirebaseJwt implements Contract
29
{
30
    /**
31
     * RsFirebaseJwt constructor.
32
     */
33
    public function __construct(
34
        protected OpenSSLAsymmetricKey|OpenSSLCertificate|string $encodeKey,
35
        protected OpenSSLAsymmetricKey|OpenSSLCertificate|string $decodeKey,
36
        protected Algorithm $algorithm,
37
    ) {
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function encode(array $payload): string
44
    {
45
        return JWT::encode($payload, $this->encodeKey, $this->algorithm->name);
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Valkyrja\Jwt\Enum\Algorithm.
Loading history...
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    public function decode(string $jwt): array
52
    {
53
        return (array) JWT::decode($jwt, new Key($this->decodeKey, $this->algorithm->name));
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Valkyrja\Jwt\Enum\Algorithm.
Loading history...
54
    }
55
}
56