Token::setId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Domain\Entities;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
use DateTimeImmutable;
9
10
class Token implements IStringerEntity
11
{
12
    protected string $id;
13
14
    protected string $apiClientId;
15
16
    protected DateTimeImmutable $expiresAt;
17
18
    protected ?DateTimeImmutable $revokedAt;
19
20
    /** @var string[] */
21
    protected array $adminResources;
22
23
    /**
24
     * Token constructor.
25
     *
26
     * @param string                 $id
27
     * @param string                 $apiClientId
28
     * @param DateTimeImmutable      $expiresAt
29
     * @param DateTimeImmutable|null $revokedAt
30
     * @param string[]               $adminResources
31
     */
32
    public function __construct(
33
        string $id,
34
        string $apiClientId,
35
        DateTimeImmutable $expiresAt,
36
        ?DateTimeImmutable $revokedAt,
37
        array $adminResources = []
38
    ) {
39
        $this->id             = $id;
40
        $this->apiClientId    = $apiClientId;
41
        $this->expiresAt      = $expiresAt;
42
        $this->revokedAt      = $revokedAt;
43
        $this->adminResources = $adminResources;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getId()
50
    {
51
        return $this->id;
52
    }
53
54
    /**
55
     * @param string $id
56
     */
57
    public function setId($id)
58
    {
59
        $this->id = $id;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getApiClientId(): string
66
    {
67
        return $this->apiClientId;
68
    }
69
70
    /**
71
     * @param string $apiClientId
72
     */
73
    public function setApiClientId(string $apiClientId): Token
74
    {
75
        $this->apiClientId = $apiClientId;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @return DateTimeImmutable
82
     */
83
    public function getExpiresAt(): DateTimeImmutable
84
    {
85
        return $this->expiresAt;
86
    }
87
88
    /**
89
     * @param DateTimeImmutable $expiresAt
90
     */
91
    public function setExpiresAt(DateTimeImmutable $expiresAt): Token
92
    {
93
        $this->expiresAt = $expiresAt;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return DateTimeImmutable|null
100
     */
101
    public function getRevokedAt(): ?DateTimeImmutable
102
    {
103
        return $this->revokedAt;
104
    }
105
106
    /**
107
     * @param DateTimeImmutable|null $revokedAt
108
     */
109
    public function setRevokedAt(?DateTimeImmutable $revokedAt): Token
110
    {
111
        $this->revokedAt = $revokedAt;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return string[]
118
     */
119
    public function getAdminResources(): array
120
    {
121
        return $this->adminResources;
122
    }
123
124
    /**
125
     * @param string[] $adminResources
126
     */
127
    public function setAdminResources(array $adminResources): void
128
    {
129
        $this->adminResources = $adminResources;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function __toString(): string
136
    {
137
        return $this->getId();
138
    }
139
140
    /**
141
     * @return array|null
142
     */
143
    public function toData(): ?array
144
    {
145
        return [
146
            "id" => $this->getId(),
147
        ];
148
    }
149
150
    /**
151
     * @return string
152
     */
153
    public function toJSON(): string
154
    {
155
        return json_encode($this->toData());
156
    }
157
}
158