Completed
Push — develop ( 5503b1...6a0d81 )
by Abdelrahman
19:31 queued 18:12
created

RefreshTokenRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Oauth\Repositories;
6
7
use Rinvex\Oauth\Bridge\RefreshToken;
8
use Illuminate\Contracts\Events\Dispatcher;
9
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
10
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
11
12
class RefreshTokenRepository implements RefreshTokenRepositoryInterface
13
{
14
    /**
15
     * The event dispatcher instance.
16
     *
17
     * @var \Illuminate\Contracts\Events\Dispatcher
18
     */
19
    protected $events;
20
21
    /**
22
     * Create a new repository instance.
23
     *
24
     * @param \Illuminate\Contracts\Events\Dispatcher $events
25
     *
26
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
     */
28
    public function __construct(Dispatcher $events)
29
    {
30
        $this->events = $events;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getNewRefreshToken()
37
    {
38
        return new RefreshToken();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity)
45
    {
46
        app('rinvex.oauth.refresh_token')->create([
47
            'identifier' => $refreshTokenEntity->getIdentifier(),
48
            'access_token_identifier' => $refreshTokenEntity->getAccessToken()->getIdentifier(),
49
            'is_revoked' => false,
50
            'expires_at' => $refreshTokenEntity->getExpiryDateTime(),
51
        ]);
52
    }
53
54
    /**
55
     * Revokes the refresh token.
56
     *
57
     * @param string $identifier
58
     *
59
     * @return mixed
60
     */
61
    public function revokeRefreshToken($identifier)
62
    {
63
        return app('rinvex.oauth.refresh_token')->where('identifier', $identifier)->update(['is_revoked' => true]);
64
    }
65
66
    /**
67
     * Checks if the refresh token has been revoked.
68
     *
69
     * @param string $identifier
70
     *
71
     * @return bool
72
     */
73
    public function isRefreshTokenRevoked($identifier)
74
    {
75
        if ($refreshToken = app('rinvex.oauth.refresh_token')->where('identifier', $identifier)->first()) {
76
            return $refreshToken->is_revoked;
77
        }
78
79
        return true;
80
    }
81
}
82