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.

RefreshTokenRepository   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getNewRefreshToken() 4 4 1
A persistNewRefreshToken() 8 8 2
A revokeRefreshToken() 9 9 2
A isRefreshTokenRevoked() 6 6 2
A createQuery() 4 4 1

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
declare(strict_types=1);
3
4
namespace Lookyman\NetteOAuth2Server\Storage\Doctrine\RefreshToken;
5
6
use Doctrine\ORM\OptimisticLockException;
7
use Doctrine\ORM\ORMInvalidArgumentException;
8
use Kdyby\Doctrine\InvalidStateException;
9
use Kdyby\Doctrine\QueryException;
10
use Kdyby\Doctrine\Registry;
11
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
12
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
13
14 View Code Duplication
class RefreshTokenRepository implements RefreshTokenRepositoryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
15
{
16
	/**
17
	 * @var Registry
18
	 */
19
	private $registry;
20
21
	/**
22
	 * @param Registry $registry
23
	 */
24
	public function __construct(Registry $registry)
25
	{
26
		$this->registry = $registry;
27
	}
28
29
	/**
30
	 * @return RefreshTokenEntity
31
	 */
32
	public function getNewRefreshToken()
33
	{
34
		return new RefreshTokenEntity();
35
	}
36
37
	/**
38
	 * @param RefreshTokenEntityInterface $refreshTokenEntity
39
	 * @throws ORMInvalidArgumentException
40
	 * @throws OptimisticLockException
41
	 */
42
	public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity)
43
	{
44
		if ($refreshTokenEntity instanceof RefreshTokenEntity) {
45
			$manager = $this->registry->getManager();
46
			$manager->persist($refreshTokenEntity);
47
			$manager->flush();
48
		}
49
	}
50
51
	/**
52
	 * @param string $tokenId
53
	 * @throws InvalidStateException
54
	 * @throws QueryException
55
	 * @throws OptimisticLockException
56
	 */
57
	public function revokeRefreshToken($tokenId)
58
	{
59
		$manager = $this->registry->getManager();
60
		/** @var RefreshTokenEntity|null $refreshTokenEntity */
61
		if ($refreshTokenEntity = $manager->getRepository(RefreshTokenEntity::class)->fetchOne($this->createQuery()->byIdentifier($tokenId))) {
62
			$refreshTokenEntity->setRevoked(true);
63
			$manager->flush();
64
		}
65
	}
66
67
	/**
68
	 * @param string $tokenId
69
	 * @return bool
70
	 * @throws InvalidStateException
71
	 * @throws QueryException
72
	 */
73
	public function isRefreshTokenRevoked($tokenId)
74
	{
75
		/** @var RefreshTokenEntity $refreshTokenEntity */
76
		$refreshTokenEntity = $this->registry->getManager()->getRepository(RefreshTokenEntity::class)->fetchOne($this->createQuery()->byIdentifier($tokenId));
77
		return $refreshTokenEntity ? $refreshTokenEntity->isRevoked() : true;
78
	}
79
80
	/**
81
	 * @return RefreshTokenQuery
82
	 */
83
	protected function createQuery(): RefreshTokenQuery
84
	{
85
		return new RefreshTokenQuery();
86
	}
87
}
88