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.

ResourcePresenter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 5
lcom 1
cbo 8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkRequirements() 0 25 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\UI;
5
6
use League\OAuth2\Server\Exception\OAuthServerException;
7
use League\OAuth2\Server\ResourceServer;
8
use Nette\Application\AbortException;
9
use Nette\Application\UI\ComponentReflection;
10
use Nette\Application\UI\Presenter;
11
use Nette\Http\IResponse;
12
use Psr\Http\Message\ServerRequestInterface;
13
use Psr\Log\LoggerAwareInterface;
14
use Psr\Log\LoggerAwareTrait;
15
16
/**
17
 * @method void onAuthorized(ServerRequestInterface $request)
18
 */
19
abstract class ResourcePresenter extends Presenter implements LoggerAwareInterface
20
{
21
	use LoggerAwareTrait;
22
	use Psr7Trait;
23
24
	/**
25
	 * @var callable[]
26
	 */
27
	public $onAuthorized;
28
29
	/**
30
	 * @var ResourceServer
31
	 * @inject
32
	 */
33
	public $resourceServer;
34
35
	/**
36
	 * @param mixed $element
37
	 * @throws AbortException
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
			$this->sendResponse($e->generateHttpResponse($response));
0 ignored issues
show
Documentation introduced by
$e->generateHttpResponse($response) is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a object<Nette\Application\IResponse>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
53
		} catch (\Exception $e) {
54
			if ($this->logger) {
55
				$this->logger->error($e->getMessage(), ['exception' => $e]);
56
			}
57
			$body = $this->createStream();
58
			$body->write('Unknown error');
59
			$this->sendResponse($response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body));
60
		}
61
62
		$this->onAuthorized($request);
63
	}
64
}
65