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

OAuth2Presenter   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 93
Duplicated Lines 10.75 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
dl 10
loc 93
c 0
b 0
f 0
wmc 13
lcom 1
cbo 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B actionAccessToken() 7 36 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Lookyman\Nette\OAuth2\Server\UI;
6
7
use League\OAuth2\Server\AuthorizationServer;
8
use League\OAuth2\Server\Exception\OAuthServerException;
9
use Lookyman\Nette\OAuth2\Server\Psr7\ApplicationPsr7ResponseInterface;
10
use Lookyman\Nette\OAuth2\Server\RedirectConfig;
11
use Lookyman\Nette\OAuth2\Server\Storage\IAuthorizationRequestSerializer;
12
use Nette\Application\AbortException;
13
use Nette\Application\UI\Presenter;
14
use Nette\Http\IRequest;
15
use Nette\Http\IResponse;
16
use Psr\Log\LoggerAwareInterface;
17
use Psr\Log\LoggerAwareTrait;
18
19
final class OAuth2Presenter extends Presenter implements LoggerAwareInterface
20
{
21
	use LoggerAwareTrait;
22
	use Psr7Trait;
23
24
	const SESSION_NAMESPACE = 'nette-oauth2-server';
25
26
	/**
27
	 * @var IAuthorizationRequestSerializer
28
	 * @inject
29
	 */
30
	public $authorizationRequestSerializer;
31
32
	/**
33
	 * @var AuthorizationServer
34
	 * @inject
35
	 */
36
	public $authorizationServer;
37
38
	/**
39
	 * @var RedirectConfig
40
	 * @inject
41
	 */
42
	public $redirectConfig;
43
44
	public function actionAccessToken()
45
	{
46
		$response = $this->createResponse();
47
48 View Code Duplication
		if (!$this->getHttpRequest()->isMethod(IRequest::POST)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
			$body = $this->createStream();
50
			$body->write('Method not allowed');
51
			/** @var ApplicationPsr7ResponseInterface $response */
52
			$response = $response->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body);
53
			$this->sendResponse($response);
54
		}
55
56
		try {
57
			/** @var ApplicationPsr7ResponseInterface $response */
58
			$response = $this->authorizationServer->respondToAccessTokenRequest($this->createServerRequest(), $response);
59
			$this->sendResponse($response);
60
61
		} catch (AbortException $e) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\AbortException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
62
			throw $e;
63
64
		} catch (OAuthServerException $e) {
0 ignored issues
show
Bug introduced by
The class League\OAuth2\Server\Exc...on\OAuthServerException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
65
			/** @var ApplicationPsr7ResponseInterface $response */
66
			$response = $e->generateHttpResponse($response);
67
			$this->sendResponse($response);
68
69
		} catch (\Throwable $e) {
70
			if ($this->logger) {
71
				$this->logger->error($e->getMessage(), ['exception' => $e]);
72
			}
73
			$body = $this->createStream();
74
			$body->write('Unknown error');
75
			/** @var ApplicationPsr7ResponseInterface $response */
76
			$response = $response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body);
77
			$this->sendResponse($response);
78
		}
79
	}
80
81
	public function actionAuthorize()
82
	{
83
		$response = $this->createResponse();
84
85 View Code Duplication
		if (!$this->getHttpRequest()->isMethod(IRequest::GET)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
			$body = $this->createStream();
87
			$body->write('Method not allowed');
88
			/** @var ApplicationPsr7ResponseInterface $response */
89
			$response = $response->withStatus(IResponse::S405_METHOD_NOT_ALLOWED)->withBody($body);
90
			$this->sendResponse($response);
91
		}
92
93
		try {
94
			$this->getSession(self::SESSION_NAMESPACE)->authorizationRequest = $this->authorizationRequestSerializer->serialize(
95
				$this->authorizationServer->validateAuthorizationRequest($this->createServerRequest())
96
			);
97
			if (!$this->getUser()->isLoggedIn()) {
98
				$this->redirectConfig->redirectToLoginDestination($this);
99
			}
100
			$this->redirectConfig->redirectToApproveDestination($this);
101
102
		} catch (AbortException $e) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\AbortException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
103
			throw $e;
104
105
		} catch (OAuthServerException $e) {
0 ignored issues
show
Bug introduced by
The class League\OAuth2\Server\Exc...on\OAuthServerException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
106
			/** @var ApplicationPsr7ResponseInterface $response */
107
			$response = $e->generateHttpResponse($response);
108
			$this->sendResponse($response);
109
110
		} catch (\Throwable $e) {
111
			if ($this->logger) {
112
				$this->logger->error($e->getMessage(), ['exception' => $e]);
113
			}
114
			$body = $this->createStream();
115
			$body->write('Unknown error');
116
			/** @var ApplicationPsr7ResponseInterface $response */
117
			$response = $response->withStatus(IResponse::S500_INTERNAL_SERVER_ERROR)->withBody($body);
118
			$this->sendResponse($response);
119
		}
120
	}
121
122
}
123