Completed
Push — master ( a206dc...d306f8 )
by Derek Stephen
02:37
created

RefreshTokenRepository::getRefreshToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 2
eloc 7
nc 2
nop 1
crap 6
1
<?php
2
3
namespace OAuth\Repository;
4
5
use DateTime;
6
use Doctrine\ORM\EntityRepository;
7
use OAuth\RefreshToken;
8
use OAuth2\Storage\RefreshTokenInterface;
9
10
class RefreshTokenRepository extends EntityRepository implements RefreshTokenInterface
11
{
12 View Code Duplication
    public function getRefreshToken($refreshToken)
0 ignored issues
show
Duplication introduced by
This method 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
        $refreshToken = $this->findOneBy(['refresh_token' => $refreshToken]);
15
        if ($refreshToken) {
16
            $refreshToken = $refreshToken->toArray();
17
            /** @var DateTime $date */
18
            $date = $refreshToken['expires'];
19
            $refreshToken['expires'] = $date->getTimestamp();
20
        }
21
        return $refreshToken;
22
    }
23
24 View Code Duplication
    public function setRefreshToken($refreshToken, $clientIdentifier, $userEmail, $expires, $scope = null)
0 ignored issues
show
Duplication introduced by
This method 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...
25
    {
26
        $client = $this->_em->getRepository('YourNamespace\Entity\OAuthClient')
27
            ->findOneBy(['client_identifier' => $clientIdentifier]);
28
        $user = $this->_em->getRepository('YourNamespace\Entity\OAuthUser')
29
            ->findOneBy(['email' => $userEmail]);
30
        $refreshToken = RefreshToken::fromArray([
31
            'refresh_token'  => $refreshToken,
32
            'client'         => $client,
33
            'user'           => $user,
34
            'expires'        => (new \DateTime())->setTimestamp($expires),
35
            'scope'          => $scope,
36
        ]);
37
        $this->_em->persist($refreshToken);
38
        $this->_em->flush();
39
    }
40
41
    public function unsetRefreshToken($refreshToken)
42
    {
43
        $refreshToken = $this->findOneBy(['refresh_token' => $refreshToken]);
44
        $this->_em->remove($refreshToken);
0 ignored issues
show
Bug introduced by
It seems like $refreshToken defined by $this->findOneBy(array('...ken' => $refreshToken)) on line 43 can also be of type null; however, Doctrine\ORM\EntityManager::remove() does only seem to accept object, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
45
        $this->_em->flush();
46
    }
47
}