Failed Conditions
Push — ng ( 977556...d85ce7 )
by Florent
03:52
created

InitialAccessTokenRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A find() 0 4 2
A save() 0 4 1
A createInitialAccessTokens() 0 20 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\Bundle\Tests\TestBundle\Entity;
15
16
use OAuth2Framework\Component\ClientRegistrationEndpoint\InitialAccessToken;
17
use OAuth2Framework\Component\ClientRegistrationEndpoint\InitialAccessTokenId;
18
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
19
20
class InitialAccessTokenRepository implements \OAuth2Framework\Component\ClientRegistrationEndpoint\InitialAccessTokenRepository
21
{
22
    /**
23
     * @var InitialAccessToken[]
24
     */
25
    private $initialAccessTokens = [];
26
27
    public function __construct()
28
    {
29
        $this->createInitialAccessTokens();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function find(InitialAccessTokenId $initialAccessTokenId): ? InitialAccessToken
36
    {
37
        return array_key_exists($initialAccessTokenId->getValue(), $this->initialAccessTokens) ? $this->initialAccessTokens[$initialAccessTokenId->getValue()] : null;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function save(InitialAccessToken $initialAccessToken)
44
    {
45
        $this->initialAccessTokens[$initialAccessToken->getTokenId()->getValue()] = $initialAccessToken;
46
    }
47
48
    private function createInitialAccessTokens()
49
    {
50
        $iat = InitialAccessToken::createEmpty();
51
        $iat = $iat->create(
52
            InitialAccessTokenId::create('VALID_INITIAL_ACCESS_TOKEN_ID'),
53
            UserAccountId::create('john.1'),
54
            new \DateTimeImmutable('now +1 day')
55
        );
56
        $iat->eraseMessages();
57
        $this->save($iat);
58
59
        $iat = InitialAccessToken::createEmpty();
60
        $iat = $iat->create(
61
            InitialAccessTokenId::create('EXPIRED_INITIAL_ACCESS_TOKEN_ID'),
62
            UserAccountId::create('john.1'),
63
            new \DateTimeImmutable('now -1 day')
64
        );
65
        $iat->eraseMessages();
66
        $this->save($iat);
67
    }
68
}
69