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:41
created

UserRepository::__construct()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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