Failed Conditions
Push — master ( c24b3a...b512e9 )
by Florent
14:42
created

AccessTokenAddedToRefreshTokenEvent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 88
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSchema() 0 4 1
A create() 0 4 1
A getRefreshTokenId() 0 4 1
A getAccessTokenId() 0 4 1
A getDomainId() 0 4 1
A getPayload() 0 6 1
A createFromJson() 0 7 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\RefreshTokenGrant\Event;
15
16
use OAuth2Framework\Component\Core\AccessToken\AccessTokenId;
17
use OAuth2Framework\Component\Core\Event\Event;
18
use OAuth2Framework\Component\Core\Id\Id;
19
use OAuth2Framework\Component\RefreshTokenGrant\RefreshTokenId;
20
use OAuth2Framework\Component\Core\Domain\DomainObject;
21
22
class AccessTokenAddedToRefreshTokenEvent extends Event
23
{
24
    /**
25
     * @var RefreshTokenId
26
     */
27
    private $refreshTokenId;
28
29
    /**
30
     * @var AccessTokenId
31
     */
32
    private $accessTokenId;
33
34
    /**
35
     * AccessTokenAddedToRefreshTokenEvent constructor.
36
     *
37
     * @param RefreshTokenId $refreshTokenId
38
     * @param AccessTokenId  $accessTokenId
39
     */
40
    protected function __construct(RefreshTokenId $refreshTokenId, AccessTokenId $accessTokenId)
41
    {
42
        $this->refreshTokenId = $refreshTokenId;
43
        $this->accessTokenId = $accessTokenId;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public static function getSchema(): string
50
    {
51
        return 'https://oauth2-framework.spomky-labs.com/schemas/events/refresh-token/access-token-added/1.0/schema';
52
    }
53
54
    /**
55
     * @param RefreshTokenId $refreshTokenId
56
     * @param AccessTokenId  $accessTokenId
57
     *
58
     * @return AccessTokenAddedToRefreshTokenEvent
59
     */
60
    public static function create(RefreshTokenId $refreshTokenId, AccessTokenId $accessTokenId): self
61
    {
62
        return new self($refreshTokenId, $accessTokenId);
63
    }
64
65
    /**
66
     * @return RefreshTokenId
67
     */
68
    public function getRefreshTokenId(): RefreshTokenId
69
    {
70
        return $this->refreshTokenId;
71
    }
72
73
    /**
74
     * @return AccessTokenId
75
     */
76
    public function getAccessTokenId(): AccessTokenId
77
    {
78
        return $this->accessTokenId;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function getDomainId(): Id
85
    {
86
        return $this->getRefreshTokenId();
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getPayload()
93
    {
94
        return (object) [
95
            'access_token_id' => $this->accessTokenId->getValue(),
96
        ];
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public static function createFromJson(\stdClass $json): DomainObject
103
    {
104
        $refreshTokenId = RefreshTokenId::create($json->domain_id);
105
        $accessTokenId = AccessTokenId::create($json->payload->access_token_id);
106
107
        return new self($refreshTokenId, $accessTokenId);
108
    }
109
}
110