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::getClientEntity()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 8
nop 4
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