Completed
Push — master ( 9628d6...a206dc )
by Derek Stephen
09:38
created

AccessTokenRepository::setAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 11
cp 0
cc 1
eloc 11
nc 1
nop 5
crap 2
1
<?php
2
3
namespace OAuth\Repository;
4
5
use DateTime;
6
use Doctrine\ORM\EntityRepository;
7
use OAuth2\Storage\AccessTokenInterface;
8
use OAuth\AccessToken;
9
10
class AccessTokenRepository extends EntityRepository implements AccessTokenInterface
11
{
12
    /**
13
     * @param $oauthToken
14
     * @return null|array
15
     */
16 View Code Duplication
    public function getAccessToken($oauthToken)
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...
17
    {
18
        /** @var AccessToken $token */
19
        $token = $this->findOneBy(['token' => $oauthToken]);
20
        if ($token instanceof AccessToken) {
21
            $array = (array) $token->toArray();
22
            /** @var DateTime $date */
23
            $date = $array['expires'];
24
            $array['expires'] = $date->getTimestamp();
25
            return $array;
26
        }
27
        return null;
28
    }
29
30
    /**
31
     * @param string $oauthToken
32
     * @param string $clientId
0 ignored issues
show
Documentation introduced by
There is no parameter named $clientId. Did you maybe mean $clientIdentifier?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
33
     * @param string $userId
0 ignored issues
show
Bug introduced by
There is no parameter named $userId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
34
     * @param int $expires
35
     * @param null $scope
36
     */
37
    public function setAccessToken($oauthToken, $clientIdentifier, $userEmail, $expires, $scope = null)
38
    {
39
        $client = $this->_em->getRepository('OAuth\Client')->findOneBy(['client_identifier' => $clientIdentifier]);
40
        $user = $this->_em->getRepository('OAuth\User')->findOneBy(['email' => $userEmail]);
41
        $token = AccessToken::fromArray([
42
            'token'     => $oauthToken,
43
            'client'    => $client,
44
            'user'      => $user,
45
            'expires'   => (new DateTime())->setTimestamp($expires),
46
            'scope'     => $scope,
47
        ]);
48
        $this->_em->persist($token);
49
        $this->_em->flush();
50
    }
51
52
}