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

ApprovePresenterTrait::createComponentApprove()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
rs 8.5906
cc 5
eloc 13
nc 12
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Lookyman\Nette\OAuth2\Server\UI;
6
7
use Lookyman\Nette\OAuth2\Server\Psr7\ApplicationPsr7ResponseInterface;
8
use Lookyman\Nette\OAuth2\Server\Storage\IAuthorizationRequestSerializer;
9
use Lookyman\Nette\OAuth2\Server\User\UserEntity;
10
use Nette\Application\IResponse;
11
use Nette\Http\IResponse as HttpResponse;
12
use Nextras\Application\UI\SecuredLinksPresenterTrait;
13
14
trait ApprovePresenterTrait
15
{
16
	use SecuredLinksPresenterTrait;
17
18
	/**
19
	 * @var IApproveControlFactory
20
	 * @inject
21
	 */
22
	public $approveControlFactory;
23
24
	/**
25
	 * @var IAuthorizationRequestSerializer
26
	 * @inject
27
	 */
28
	public $authorizationRequestSerializer;
29
30
	/**
31
	 * @var RedirectService
32
	 * @inject
33
	 */
34
	public $redirectService;
35
36
	protected function createComponentApprove(): ApproveControl
37
	{
38
		if (!$this->getUser()->isLoggedIn()) {
39
			$this->redirectService->redirectToLoginDestination($this);
40
		}
41
42
		/** @var string $data */
43
		$data = $this->getSession(OAuth2Presenter::SESSION_NAMESPACE)->authorizationRequest;
44
		$authorizationRequest = $data ? $this->authorizationRequestSerializer->unserialize($data) : null;
45
46
		if ($authorizationRequest) {
47
			if (!$authorizationRequest->getUser()) {
48
				$authorizationRequest->setUser(new UserEntity($this->getUser()->getId()));
49
			}
50
			$control = $this->approveControlFactory->create($authorizationRequest);
51
			$control->onResponse[] = function (ApplicationPsr7ResponseInterface $response) {
52
				$this->sendResponse($response);
53
			};
54
			return $control;
55
		}
56
57
		$this->error(null, HttpResponse::S400_BAD_REQUEST);
58
	}
59
60
	/**
61
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
62
	 */
63
	abstract public function error($message = null, $code = HttpResponse::S404_NOT_FOUND);
64
65
	/**
66
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
67
	 */
68
	abstract public function getSession($namespace = null);
69
70
	abstract public function getUser();
71
72
	abstract public function sendResponse(IResponse $response);
73
74
}
75