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.

UserRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 4
A getUserEntityByUserCredentials() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\User;
5
6
use League\OAuth2\Server\Entities\ClientEntityInterface;
7
use League\OAuth2\Server\Entities\UserEntityInterface;
8
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
9
use Nette\Security\User;
10
11
class UserRepository implements UserRepositoryInterface
12
{
13
	/**
14
	 * @var User
15
	 */
16
	private $user;
17
18
	/**
19
	 * @var callable
20
	 */
21
	private $credentialsValidator;
22
23
	/**
24
	 * @param User $user
25
	 * @param callable|null $credentialsValidator
26
	 */
27
	public function __construct(User $user, callable $credentialsValidator = null)
28
	{
29
		$this->user = $user;
30
		$this->credentialsValidator = $credentialsValidator ?: function () {
31
			$this->user->logout(true);
32
			try {
33
				$this->user->login(...func_get_args());
34
35
			} catch (\Exception $e) {} // Fail silently
36
37
			return $this->user->isLoggedIn() ? new UserEntity($this->user->getId()) : null;
38
		};
39
	}
40
41
	/**
42
	 * @param string $username
43
	 * @param string $password
44
	 * @param string $grantType
45
	 * @param ClientEntityInterface $clientEntity
46
	 * @return UserEntityInterface|null
47
	 */
48
	public function getUserEntityByUserCredentials(
49
		$username,
50
		$password,
51
		$grantType,
52
		ClientEntityInterface $clientEntity
53
	)
54
	{
55
		return call_user_func($this->credentialsValidator, $username, $password, $grantType, $clientEntity);
56
	}
57
}
58