Completed
Pull Request — master (#736)
by
unknown
59:12 queued 56:55
created

FluentRefreshToken::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 15
loc 15
ccs 12
cts 12
cp 1
rs 9.4285
cc 1
eloc 11
nc 1
nop 3
crap 1
1
<?php
2
3
/*
4
 * This file is part of OAuth 2.0 Laravel.
5
 *
6
 * (c) Luca Degasperi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LucaDegasperi\OAuth2Server\Storage;
13
14
use Carbon\Carbon;
15
use League\OAuth2\Server\Entity\RefreshTokenEntity;
16
use League\OAuth2\Server\Storage\RefreshTokenInterface;
17
18
/**
19
 * This is the fluent refresh token class.
20
 *
21
 * @author Luca Degasperi <[email protected]>
22
 */
23
class FluentRefreshToken extends AbstractFluentAdapter implements RefreshTokenInterface
24
{
25
    /**
26
     * Return a new instance of \League\OAuth2\Server\Entity\RefreshTokenEntity.
27
     *
28
     * @param string $token
29
     *
30
     * @return \League\OAuth2\Server\Entity\RefreshTokenEntity
0 ignored issues
show
Documentation introduced by
Should the return type not be RefreshTokenEntity|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
31
     */
32 9 View Code Duplication
    public function get($token)
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...
33
    {
34 9
        $result = $this->getConnection()->table('oauth_refresh_tokens')
35 9
                ->where('oauth_refresh_tokens.id', $token)
36 9
                ->where('oauth_refresh_tokens.expire_time', '>=', time())
37 9
                ->first();
38
39 9
        if (is_null($result)) {
40 6
            return;
41
        }
42
43 3
        return (new RefreshTokenEntity($this->getServer()))
44 3
               ->setId($result->id)
45 3
               ->setAccessTokenId($result->access_token_id)
46 3
               ->setExpireTime((int) $result->expire_time);
47
    }
48
49
    /**
50
     * Create a new refresh token_name.
51
     *
52
     * @param  string $token
53
     * @param  int $expireTime
54
     * @param  string $accessToken
55
     *
56
     * @return \League\OAuth2\Server\Entity\RefreshTokenEntity
57
     */
58 3 View Code Duplication
    public function create($token, $expireTime, $accessToken)
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...
59
    {
60 3
        $this->getConnection()->table('oauth_refresh_tokens')->insert([
61 3
            'id' => $token,
62 3
            'expire_time' => $expireTime,
63 3
            'access_token_id' => $accessToken,
64 3
            'created_at' => Carbon::now(),
65 3
            'updated_at' => Carbon::now(),
66 3
        ]);
67
68 3
        return (new RefreshTokenEntity($this->getServer()))
69 3
               ->setId($token)
70 3
               ->setAccessTokenId($accessToken)
71 3
               ->setExpireTime((int) $expireTime);
72
    }
73
74
    /**
75
     * Delete the refresh token.
76
     *
77
     * @param  \League\OAuth2\Server\Entity\RefreshTokenEntity $token
78
     *
79
     * @return void
80
     */
81 3
    public function delete(RefreshTokenEntity $token)
82
    {
83 3
        $this->getConnection()->table('oauth_refresh_tokens')
84 3
        ->where('id', $token->getId())
85 3
        ->delete();
86 3
    }
87
}
88