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::serialize()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 3
eloc 7
nc 4
nop 1
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