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.

LoginSubscriber   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 3
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onPresenter() 0 4 1
A onLoggedIn() 0 9 4
A getSubscribedEvents() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\User;
5
6
use Kdyby\Events\Subscriber;
7
use Lookyman\NetteOAuth2Server\RedirectConfig;
8
use Lookyman\NetteOAuth2Server\UI\OAuth2Presenter;
9
use Nette\Application\AbortException;
10
use Nette\Application\Application;
11
use Nette\Application\IPresenter;
12
use Nette\Application\UI\Presenter;
13
use Nette\InvalidStateException;
14
use Nette\Security\User;
15
16
class LoginSubscriber implements Subscriber
17
{
18
	/**
19
	 * @var IPresenter|null
20
	 */
21
	private $presenter;
22
23
	/**
24
	 * @var int
25
	 */
26
	private $priority;
27
28
	/**
29
	 * @var RedirectConfig
30
	 */
31
	private $redirectConfig;
32
33
	/**
34
	 * @param RedirectConfig $redirectConfig
35
	 * @param int $priority
36
	 */
37
	public function __construct(RedirectConfig $redirectConfig, int $priority = 0)
38
	{
39
		$this->redirectConfig = $redirectConfig;
40
		$this->priority = $priority;
41
	}
42
43
	/**
44
	 * @param Application $application
45
	 * @param IPresenter $presenter
46
	 */
47
	public function onPresenter(Application $application, IPresenter $presenter)
0 ignored issues
show
Unused Code introduced by
The parameter $application is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
	{
49
		$this->presenter = $presenter;
50
	}
51
52
	/**
53
	 * @param User $user
54
	 * @throws InvalidStateException
55
	 * @throws AbortException
56
	 */
57
	public function onLoggedIn(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
	{
59
		if (!$this->presenter) {
60
			throw new InvalidStateException('Presenter not set');
61
		}
62
		if ($this->presenter instanceof Presenter && $this->presenter->getSession(OAuth2Presenter::SESSION_NAMESPACE)->authorizationRequest) {
63
			$this->presenter->redirect(...$this->redirectConfig->getApproveDestination());
64
		}
65
	}
66
67
	/**
68
	 * @return array
69
	 */
70
	public function getSubscribedEvents()
71
	{
72
		return [
73
			Application::class . '::onPresenter',
74
			User::class . '::onLoggedIn' => [
75
				['onLoggedIn', $this->priority],
76
			],
77
		];
78
	}
79
}
80