Completed
Push — master ( 37a451...0fec48 )
by Artem
01:36
created

JwtPayload::getPayloadData()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.2248
c 0
b 0
f 0
cc 5
nc 16
nop 0
1
<?php
2
/*
3
 * This file is part of the FreshCentrifugoBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\CentrifugoBundle\Token;
14
15
/**
16
 * JwtPayload.
17
 *
18
 * @see https://centrifugal.github.io/centrifugo/server/authentication/#claims
19
 *
20
 * @author Artem Henvald <[email protected]>
21
 */
22
final class JwtPayload extends AbstractJwtPayload
23
{
24
    private string $subject;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
25
26
    /** @var string[] */
27
    private array $channels;
28
29
    /**
30
     * @param string      $subject
31
     * @param array       $info
32
     * @param int|null    $expirationTime
33
     * @param string|null $base64info
34
     * @param string[]    $channels
35
     */
36
    public function __construct(string $subject, array $info = [], ?int $expirationTime = null, ?string $base64info = null, array $channels = [])
37
    {
38
        $this->subject = $subject;
39
        $this->channels = $channels;
40
41
        parent::__construct($info, $expirationTime, $base64info);
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getSubject(): string
48
    {
49
        return $this->subject;
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function getChannels(): array
56
    {
57
        return $this->channels;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getPayloadData(): array
64
    {
65
        $data = [
66
            'sub' => $this->getSubject(),
67
        ];
68
69
        if (null !== $this->getExpirationTime()) {
70
            $data['exp'] = $this->getExpirationTime();
71
        }
72
73
        if (!empty($this->getInfo())) {
74
            $data['info'] = $this->getInfo();
75
        }
76
77
        if (null !== $this->getBase64Info()) {
78
            $data['b64info'] = $this->getBase64Info();
79
        }
80
81
        if (!empty($this->getChannels())) {
82
            $data['channels'] = $this->getChannels();
83
        }
84
85
        return $data;
86
    }
87
}
88