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

RedirectConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Lookyman\Nette\OAuth2\Server;
6
7
use Nette\Application\UI\Component;
8
use Nette\InvalidStateException;
9
use Nette\SmartObject;
10
11
/**
12
 * @method void onBeforeApproveRedirect(RedirectConfig $redirectConfig)
13
 * @method void onBeforeLoginRedirect(RedirectConfig $redirectConfig)
14
 */
15
final class RedirectConfig
16
{
17
	use SmartObject;
18
19
	/**
20
	 * @var callable[]
21
	 */
22
	public $onBeforeApproveRedirect = [];
23
24
	/**
25
	 * @var callable[]
26
	 */
27
	public $onBeforeLoginRedirect = [];
28
29
	/**
30
	 * @var array
31
	 */
32
	private $approveDestination;
33
34
	/**
35
	 * @var array
36
	 */
37
	private $loginDestination;
38
39
	/**
40
	 * @param string|array|null $approveDestination
41
	 * @param string|array|null $loginDestination
42
	 */
43
	public function __construct($approveDestination, $loginDestination)
44
	{
45
		$this->setApproveDestination($approveDestination);
46
		$this->setLoginDestination($loginDestination);
47
	}
48
49
	/**
50
	 * @param string|array|null $approveDestination
51
	 */
52
	public function setApproveDestination($approveDestination)
53
	{
54
		$this->approveDestination = (array) $approveDestination;
55
	}
56
57
	public function redirectToApproveDestination(Component $component)
58
	{
59
		if (empty($this->approveDestination)) {
60
			throw new InvalidStateException('Approve destination not set');
61
		}
62
		$this->onBeforeApproveRedirect($this);
63
		$component->redirect(...$this->approveDestination);
64
	}
65
66
	/**
67
	 * @param string|array|null $loginDestination
68
	 */
69
	public function setLoginDestination($loginDestination)
70
	{
71
		$this->loginDestination = (array) $loginDestination;
72
	}
73
74
	public function redirectToLoginDestination(Component $component)
75
	{
76
		if (empty($this->loginDestination)) {
77
			throw new InvalidStateException('Login destination not set');
78
		}
79
		$this->onBeforeLoginRedirect($this);
80
		$component->redirect(...$this->loginDestination);
81
	}
82
83
}
84