GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3ae4c4...a52273 )
by Lukáš
02:32 queued 14s
created

ScopeRepository::createQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\Storage\Doctrine\Scope;
5
6
use Kdyby\Doctrine\EntityManager;
7
use Kdyby\Doctrine\EntityRepository;
8
use Kdyby\Doctrine\QueryObject;
9
use League\OAuth2\Server\Entities\ClientEntityInterface;
10
use League\OAuth2\Server\Entities\ScopeEntityInterface;
11
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
12
13
class ScopeRepository implements ScopeRepositoryInterface
14
{
15
	/**
16
	 * @var EntityManager
17
	 */
18
	private $entityManager;
19
20
	/**
21
	 * @var EntityRepository
22
	 */
23
	private $repository;
24
25
	/**
26
	 * @param EntityManager $entityManager
27
	 */
28
	public function __construct(EntityManager $entityManager)
0 ignored issues
show
Bug introduced by
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
29
	{
30
		$this->entityManager = $entityManager;
31
		$this->repository = $entityManager->getRepository(ScopeEntity::class);
32
	}
33
34
	/**
35
	 * @param string $identifier
36
	 * @return ScopeEntityInterface
37
	 */
38
	public function getScopeEntityByIdentifier($identifier)
39
	{
40
		return $this->repository->fetchOne($this->createQuery()->byIdentifier($identifier));
41
	}
42
43
	/**
44
	 * @param array $scopes
45
	 * @param string $grantType
46
	 * @param ClientEntityInterface $clientEntity
47
	 * @param string|null $userIdentifier
48
	 * @return ScopeEntityInterface[]
49
	 */
50
	public function finalizeScopes(
51
		array $scopes,
52
		$grantType,
53
		ClientEntityInterface $clientEntity,
54
		$userIdentifier = null
55
	)
56
	{
57
		return $scopes;
58
	}
59
60
	/**
61
	 * @return QueryObject
62
	 */
63
	protected function createQuery(): QueryObject
64
	{
65
		return new ScopeQuery();
66
	}
67
}
68