Failed Conditions
Push — master ( aacec5...b5a0b4 )
by Florent
04:50
created

AbstractInitialAccessToken   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 61
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getUserAccountId() 0 4 1
A getExpiresAt() 0 4 1
A hasExpired() 0 4 2
A isRevoked() 0 4 1
A markAsRevoked() 0 4 1
A jsonSerialize() 0 11 3
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;
15
16
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
17
18
abstract class AbstractInitialAccessToken implements InitialAccessToken
19
{
20
    /**
21
     * @var bool
22
     */
23
    private $revoked;
24
25
    /**
26
     * @var \DateTimeImmutable|null
27
     */
28
    private $expiresAt;
29
30
    /**
31
     * @var UserAccountId|null
32
     */
33
    private $userAccountId;
34
35
    public function __construct(?UserAccountId $userAccountId, ?\DateTimeImmutable $expiresAt)
36
    {
37
        $this->expiresAt = $expiresAt;
38
        $this->userAccountId = $userAccountId;
39
        $this->revoked = false;
40
    }
41
42
    public function getUserAccountId(): ?UserAccountId
43
    {
44
        return $this->userAccountId;
45
    }
46
47
    public function getExpiresAt(): ?\DateTimeImmutable
48
    {
49
        return $this->expiresAt;
50
    }
51
52
    public function hasExpired(): bool
53
    {
54
        return null !== $this->getExpiresAt() ? $this->expiresAt->getTimestamp() < \time() : false;
55
    }
56
57
    public function isRevoked(): bool
58
    {
59
        return $this->revoked;
60
    }
61
62
    public function markAsRevoked(): void
63
    {
64
        $this->revoked = true;
65
    }
66
67
    public function jsonSerialize()
68
    {
69
        $data = [
70
            'initial_access_token_id' => $this->getId()->getValue(),
71
            'user_account_id' => null !== $this->getUserAccountId() ? $this->getUserAccountId()->getValue() : null,
72
            'expires_at' => null !== $this->getExpiresAt() ? $this->getExpiresAt()->getTimestamp() : null,
73
            'is_revoked' => $this->isRevoked(),
74
        ];
75
76
        return $data;
77
    }
78
}
79