Failed Conditions
Push — master ( 3df084...2d5f15 )
by Florent
06:05
created

RefreshTokenRepository::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\ServerBundle\Tests\TestBundle\Entity;
15
16
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
17
use Doctrine\Common\Persistence\ManagerRegistry;
18
use OAuth2Framework\Component\Core\Client\ClientId;
19
use OAuth2Framework\Component\Core\DataBag\DataBag;
20
use OAuth2Framework\Component\Core\ResourceOwner\ResourceOwnerId;
21
use OAuth2Framework\Component\Core\ResourceServer\ResourceServerId;
22
use OAuth2Framework\Component\RefreshTokenGrant\RefreshToken as CoreRefreshToken;
23
use OAuth2Framework\Component\RefreshTokenGrant\RefreshTokenId;
24
use OAuth2Framework\Component\RefreshTokenGrant\RefreshTokenRepository as RefreshTokenRepositoryInterface;
25
26
final class RefreshTokenRepository implements RefreshTokenRepositoryInterface, ServiceEntityRepositoryInterface
27
{
28
    private $entityRepository;
29
    private $entityManager;
30
31
    public function __construct(ManagerRegistry $managerRegistry)
32
    {
33
        $this->entityManager = $managerRegistry->getManagerForClass(RefreshToken::class);
34
        $this->entityRepository = $this->entityManager->getRepository(RefreshToken::class);
35
    }
36
37
    public function find(RefreshTokenId $refreshTokenId): ?CoreRefreshToken
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...
38
    {
39
        return $this->entityRepository->find($refreshTokenId);
40
    }
41
42
    public function save(CoreRefreshToken $refreshToken): void
43
    {
44
        if (!$refreshToken instanceof RefreshToken) {
45
            throw new \InvalidArgumentException('Unsupported refresh token class');
46
        }
47
        $this->entityManager->persist($refreshToken);
48
        $this->entityManager->flush();
49
    }
50
51
    public function create(ClientId $clientId, ResourceOwnerId $resourceOwnerId, \DateTimeImmutable $expiresAt, DataBag $parameter, DataBag $metadata, ?ResourceServerId $resourceServerId): CoreRefreshToken
52
    {
53
        return new RefreshToken(
54
            new RefreshTokenId(\bin2hex(\random_bytes(32))),
55
            $clientId,
56
            $resourceOwnerId,
57
            $expiresAt,
58
            $parameter,
59
            $metadata,
60
            $resourceServerId
61
        );
62
    }
63
}
64