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

AuthorizationCodeRepository::initAuthorizationCodes()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 1
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A AuthorizationCodeRepository::create() 0 14 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\AuthorizationCodeGrant\AuthorizationCode as CoreAuthorizationCode;
19
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeId;
20
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeRepository as AuthorizationCodeRepositoryInterface;
21
use OAuth2Framework\Component\Core\Client\ClientId;
22
use OAuth2Framework\Component\Core\DataBag\DataBag;
23
use OAuth2Framework\Component\Core\ResourceServer\ResourceServerId;
24
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
25
26
final class AuthorizationCodeRepository implements AuthorizationCodeRepositoryInterface, ServiceEntityRepositoryInterface
27
{
28
    private $entityRepository;
29
    private $entityManager;
30
31
    public function __construct(ManagerRegistry $managerRegistry)
32
    {
33
        $this->entityManager = $managerRegistry->getManagerForClass(AuthorizationCode::class);
34
        $this->entityRepository = $this->entityManager->getRepository(AuthorizationCode::class);
35
    }
36
37
    public function find(AuthorizationCodeId $authorizationCodeId): ?CoreAuthorizationCode
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($authorizationCodeId);
40
    }
41
42
    public function save(CoreAuthorizationCode $accessToken): void
43
    {
44
        if (!$accessToken instanceof AuthorizationCode) {
45
            throw new \InvalidArgumentException('Unsupported authorization code class');
46
        }
47
        $this->entityManager->persist($accessToken);
48
        $this->entityManager->flush();
49
    }
50
51
    public function create(ClientId $clientId, UserAccountId $userAccountId, array $queryParameters, string $redirectUri, \DateTimeImmutable $expiresAt, DataBag $parameter, DataBag $metadata, ?ResourceServerId $resourceServerId): CoreAuthorizationCode
52
    {
53
        return new AuthorizationCode(
54
            new AuthorizationCodeId(\bin2hex(\random_bytes(32))),
55
            $clientId,
56
            $userAccountId,
57
            $queryParameters,
58
            $redirectUri,
59
            $expiresAt,
60
            $parameter,
61
            $metadata,
62
            $resourceServerId
63
        );
64
    }
65
}
66