Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
RefreshTokenRepository
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 revokeRefreshTokenFromTokenId
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 revokeRefreshTokenFromToken
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Albet\SanctumRefresh\Repositories;
4
5use Albet\SanctumRefresh\Models\RefreshToken;
6
7use function Albet\SanctumRefresh\checkRefreshToken;
8
9class RefreshTokenRepository
10{
11    public function revokeRefreshTokenFromTokenId(int $tokenId): bool
12    {
13        $find = RefreshToken::where('token_id', $tokenId)->first();
14        if ($find) {
15            $find->delete();
16
17            return true;
18        }
19
20        return false;
21    }
22
23    public function revokeRefreshTokenFromToken(string $plainRefreshToken): bool
24    {
25        if (!checkRefreshToken($plainRefreshToken)) {
26            return false;
27        }
28
29        $findTokenId = explode('|', $plainRefreshToken);
30        $findTokenId = $findTokenId[array_key_first($findTokenId)];
31
32        return RefreshToken::find($findTokenId)->delete();
33    }
34}