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áš
07:03
created

ResourcePresenter::checkRequirements()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
c 0
b 0
f 0
rs 8.439
cc 5
eloc 16
nc 5
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Lookyman\Nette\OAuth2\Server\UI;
6
7
use League\OAuth2\Server\Exception\OAuthServerException;
8
use League\OAuth2\Server\ResourceServer;
9
use Lookyman\Nette\OAuth2\Server\Psr7\ApplicationPsr7ResponseInterface;
10
use Nette\Application\UI\ComponentReflection;
11
use Nette\Application\UI\Presenter;
12
use Nette\Http\IResponse;
13
use Psr\Http\Message\ServerRequestInterface;
14
use Psr\Log\LoggerAwareInterface;
15
use Psr\Log\LoggerAwareTrait;
16
17
/**
18
 * @method void onAuthorized(ServerRequestInterface $request)
19
 */
20
abstract class ResourcePresenter extends Presenter implements LoggerAwareInterface
21
{
22
	use LoggerAwareTrait;
23
	use Psr7Trait;
24
25
	/**
26
	 * @var callable[]
27
	 */
28
	public $onAuthorized;
29
30
	/**
31
	 * @var ResourceServer
32
	 * @inject
33
	 */
34
	public $resourceServer;
35
36
	/**
37
	 * @param mixed $element
38
	 */
39
	final public function checkRequirements($element)
40
	{
41
		if (!$element instanceof ComponentReflection) {
42
			return;
43
		}
44
45
		$request = $this->createServerRequest();
46
		$response = $this->createResponse();
47
		try {
48
			$request = $this->resourceServer->validateAuthenticatedRequest($request);
49
50
		} catch (OAuthServerException $e) {
51
			/** @var ApplicationPsr7ResponseInterface $response */
52
			$response = $e->generateHttpResponse($response);
53
			$this->sendResponse($response);
54
55
		} catch (\Throwable $e) {
56
			if ($this->logger) {
57
				$this->logger->error($e->getMessage(), ['exception' => $e]);
58
			}
59
			$body = $this->createStream();
60
			$body->write('Unknown error');
61
			$this->sendResponse($response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body));
62
		}
63
64
		$this->onAuthorized($request);
65
	}
66
67
}
68