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.

AuthorizationRequestSerializer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serialize() 0 11 3
A unserialize() 0 15 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\Storage\Doctrine;
5
6
use Kdyby\Doctrine\Registry;
7
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
8
use Lookyman\NetteOAuth2Server\Storage\IAuthorizationRequestSerializer;
9
10
class AuthorizationRequestSerializer implements IAuthorizationRequestSerializer
11
{
12
	/**
13
	 * @var Registry
14
	 */
15
	private $registry;
16
17
	/**
18
	 * @param Registry $registry
19
	 */
20
	public function __construct(Registry $registry)
21
	{
22
		$this->registry = $registry;
23
	}
24
25
	/**
26
	 * @param AuthorizationRequest $authorizationRequest
27
	 * @return string
28
	 */
29
	public function serialize(AuthorizationRequest $authorizationRequest): string
30
	{
31
		$manager = $this->registry->getManager();
32
		if ($authorizationRequest->getClient()) {
33
			$manager->detach($authorizationRequest->getClient());
34
		}
35
		foreach ($authorizationRequest->getScopes() as $scope) {
36
			$manager->detach($scope);
37
		}
38
		return serialize($authorizationRequest);
39
	}
40
41
	/**
42
	 * @param string $data
43
	 * @return AuthorizationRequest
44
	 */
45
	public function unserialize(string $data): AuthorizationRequest
46
	{
47
		$manager = $this->registry->getManager();
48
		/** @var AuthorizationRequest $authorizationRequest */
49
		$authorizationRequest = unserialize($data);
50
		if ($client = $authorizationRequest->getClient()) {
51
			$authorizationRequest->setClient($manager->merge($client));
52
		}
53
		$scopes = [];
54
		foreach ($authorizationRequest->getScopes() as $scope) {
55
			$scopes[] = $manager->merge($scope);
56
		}
57
		$authorizationRequest->setScopes($scopes);
58
		return $authorizationRequest;
59
	}
60
}
61