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

AccessTokenCreatedEvent::createFromJson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
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\Core\AccessToken\Event;
15
16
use OAuth2Framework\Component\Core\AccessToken\AccessTokenId;
17
use OAuth2Framework\Component\Core\Client\ClientId;
18
use OAuth2Framework\Component\Core\DataBag\DataBag;
19
use OAuth2Framework\Component\Core\Event\Event;
20
use OAuth2Framework\Component\Core\Id\Id;
21
use OAuth2Framework\Component\Core\ResourceOwner\ResourceOwnerId;
22
use OAuth2Framework\Component\Core\ResourceServer\ResourceServerId;
23
24
class AccessTokenCreatedEvent extends Event
25
{
26
    private $accessTokenId;
27
    private $expiresAt;
28
    private $resourceOwnerId;
29
    private $clientId;
30
    private $parameters;
31
    private $metadatas;
32
    private $resourceServerId;
33
34
    public function __construct(AccessTokenId $accessTokenId, ResourceOwnerId $resourceOwnerId, ClientId $clientId, DataBag $parameters, DataBag $metadatas, \DateTimeImmutable $expiresAt, ?ResourceServerId $resourceServerId)
35
    {
36
        $this->accessTokenId = $accessTokenId;
37
        $this->resourceOwnerId = $resourceOwnerId;
38
        $this->clientId = $clientId;
39
        $this->parameters = $parameters;
40
        $this->metadatas = $metadatas;
41
        $this->expiresAt = $expiresAt;
42
        $this->resourceServerId = $resourceServerId;
43
    }
44
45
    public static function getSchema(): string
46
    {
47
        return 'https://oauth2-framework.spomky-labs.com/schemas/events/access-token/created/1.0/schema';
48
    }
49
50
    public function getAccessTokenId(): AccessTokenId
51
    {
52
        return $this->accessTokenId;
53
    }
54
55
    public function getExpiresAt(): \DateTimeImmutable
56
    {
57
        return $this->expiresAt;
58
    }
59
60
    public function getResourceOwnerId(): ResourceOwnerId
61
    {
62
        return $this->resourceOwnerId;
63
    }
64
65
    public function getClientId(): ClientId
66
    {
67
        return $this->clientId;
68
    }
69
70
    public function getParameter(): DataBag
71
    {
72
        return $this->parameters;
73
    }
74
75
    public function getMetadata(): DataBag
76
    {
77
        return $this->metadatas;
78
    }
79
80
    public function getResourceServerId(): ?ResourceServerId
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...
81
    {
82
        return $this->resourceServerId;
83
    }
84
85
    public function getDomainId(): Id
86
    {
87
        return $this->getAccessTokenId();
88
    }
89
90
    public function getPayload()
91
    {
92
        return [
93
            'resource_owner_id' => $this->resourceOwnerId->getValue(),
94
            'resource_owner_class' => \get_class($this->resourceOwnerId),
95
            'client_id' => $this->clientId->getValue(),
96
            'parameters' => (object) $this->parameters->all(),
97
            'metadatas' => (object) $this->metadatas->all(),
98
            'expires_at' => $this->expiresAt->getTimestamp(),
99
            'resource_server_id' => $this->resourceServerId ? $this->resourceServerId->getValue() : null,
100
        ];
101
    }
102
}
103