Failed Conditions
Push — master ( a3629e...b4f6c5 )
by Florent
08:47
created

InitialAccessTokenCreatedEvent::createFromJson()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\ClientRegistrationEndpoint\Event;
15
16
use OAuth2Framework\Component\ClientRegistrationEndpoint\InitialAccessTokenId;
17
use OAuth2Framework\Component\Core\Event\Event;
18
use OAuth2Framework\Component\Core\Id\Id;
19
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
20
21
class InitialAccessTokenCreatedEvent extends Event
22
{
23
    private $initialAccessTokenId;
24
    private $expiresAt;
25
    private $userAccountId;
26
27
    public function __construct(InitialAccessTokenId $initialAccessTokenId, UserAccountId $userAccountId, ?\DateTimeImmutable $expiresAt)
28
    {
29
        $this->initialAccessTokenId = $initialAccessTokenId;
30
        $this->expiresAt = $expiresAt;
31
        $this->userAccountId = $userAccountId;
32
    }
33
34
    public static function getSchema(): string
35
    {
36
        return 'https://oauth2-framework.spomky-labs.com/schemas/events/initial-access-token/created/1.0/schema';
37
    }
38
39
    public function getInitialAccessTokenId(): InitialAccessTokenId
40
    {
41
        return $this->initialAccessTokenId;
42
    }
43
44
    public function getUserAccountId(): UserAccountId
45
    {
46
        return $this->userAccountId;
47
    }
48
49
    public function getExpiresAt(): ?\DateTimeImmutable
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
50
    {
51
        return $this->expiresAt;
52
    }
53
54
    public function getDomainId(): Id
55
    {
56
        return $this->getInitialAccessTokenId();
57
    }
58
59
    public function getPayload()
60
    {
61
        return [
62
            'user_account_id' => $this->userAccountId ? $this->userAccountId->getValue() : null,
63
            'expires_at' => $this->expiresAt ? $this->expiresAt->getTimestamp() : null,
64
        ];
65
    }
66
}
67