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 (#9)
by Lukáš
02:01
created

RedirectConfig::getApproveDestination()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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