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
Push — master ( 3ae4c4...a52273 )
by Lukáš
02:32 queued 14s
created

AuthCodeRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 61
loc 61
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getNewAuthCode() 4 4 1
A persistNewAuthCode() 5 5 1
A revokeAuthCode() 5 5 1
A isAuthCodeRevoked() 4 4 1
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\AuthCode;
5
6
use Kdyby\Doctrine\EntityManager;
7
use Kdyby\Doctrine\EntityRepository;
8
use Kdyby\Doctrine\QueryObject;
9
use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
10
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
11
12 View Code Duplication
class AuthCodeRepository implements AuthCodeRepositoryInterface
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...
13
{
14
	/**
15
	 * @var EntityManager
16
	 */
17
	private $entityManager;
18
19
	/**
20
	 * @var EntityRepository
21
	 */
22
	private $repository;
23
24
	public function __construct(EntityManager $entityManager)
0 ignored issues
show
Bug introduced by
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
25
	{
26
		$this->entityManager = $entityManager;
27
		$this->repository = $entityManager->getRepository(AuthCodeEntity::class);
28
	}
29
30
	/**
31
	 * @return AuthCodeEntityInterface
32
	 */
33
	public function getNewAuthCode()
34
	{
35
		return new AuthCodeEntity();
36
	}
37
38
	/**
39
	 * @param AuthCodeEntityInterface $authCodeEntity
40
	 */
41
	public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity)
42
	{
43
		$this->entityManager->persist($authCodeEntity);
44
		$this->entityManager->flush();
45
	}
46
47
	/**
48
	 * @param string $codeId
49
	 */
50
	public function revokeAuthCode($codeId)
51
	{
52
		$this->repository->fetchOne($this->createQuery()->byIdentifier($codeId))->setRevoked(true);
53
		$this->entityManager->flush();
54
	}
55
56
	/**
57
	 * @param string $codeId
58
	 * @return bool
59
	 */
60
	public function isAuthCodeRevoked($codeId)
61
	{
62
		return $this->repository->fetchOne($this->createQuery()->byIdentifier($codeId))->isRevoked();
63
	}
64
65
	/**
66
	 * @return QueryObject
67
	 */
68
	protected function createQuery(): QueryObject
69
	{
70
		return new AuthCodeQuery();
71
	}
72
}
73