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.

ClientRepository   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
B getClientEntity() 0 11 5
A createQuery() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\Storage\Doctrine\Client;
5
6
use Kdyby\Doctrine\InvalidStateException;
7
use Kdyby\Doctrine\QueryException;
8
use Kdyby\Doctrine\Registry;
9
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
10
11
class ClientRepository implements ClientRepositoryInterface
12
{
13
	/**
14
	 * @var Registry
15
	 */
16
	private $registry;
17
18
	/**
19
	 * @var callable
20
	 */
21
	private $secretValidator;
22
23
	/**
24
	 * @param Registry $registry
25
	 * @param callable|null $secretValidator
26
	 */
27
	public function __construct(Registry $registry, callable $secretValidator = null)
28
	{
29
		$this->registry = $registry;
30
		$this->secretValidator = $secretValidator ?: function ($expected, $actual) { return hash_equals($expected, $actual); };
31
	}
32
33
	/**
34
	 * @param string $clientIdentifier
35
	 * @param string $grantType
36
	 * @param string|null $clientSecret
37
	 * @param bool $mustValidateSecret
38
	 * @return ClientEntity|null
39
	 * @throws InvalidStateException
40
	 * @throws QueryException
41
	 */
42
	public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
43
	{
44
		/** @var ClientEntity|null $clientEntity */
45
		$clientEntity = $this->registry->getManager()->getRepository(ClientEntity::class)->fetchOne($this->createQuery()->byIdentifier($clientIdentifier));
46
		return $clientEntity
47
			&& $mustValidateSecret
48
			&& $clientEntity->getSecret() !== null
49
			&& !call_user_func($this->secretValidator, $clientEntity->getSecret(), $clientSecret)
50
			? null
51
			: $clientEntity;
52
	}
53
54
	/**
55
	 * @return ClientQuery
56
	 */
57
	protected function createQuery(): ClientQuery
58
	{
59
		return new ClientQuery();
60
	}
61
}
62