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
Pull Request — master (#10)
by Lukáš
01:47
created

UserRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

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