Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
WithRefreshable | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
refreshToken | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Albet\SanctumRefresh\Traits; |
4 | |
5 | use Albet\SanctumRefresh\Exceptions\InvalidModelException; |
6 | use Albet\SanctumRefresh\Models\RefreshToken; |
7 | use Illuminate\Database\Eloquent\Model; |
8 | use Illuminate\Database\Eloquent\Relations\HasOne; |
9 | use ReflectionClass; |
10 | |
11 | trait WithRefreshable |
12 | { |
13 | /** |
14 | * @throws InvalidModelException |
15 | */ |
16 | public function refreshToken(): HasOne |
17 | { |
18 | if (! in_array(Model::class, class_parents($this))) { |
19 | throw new InvalidModelException((new ReflectionClass($this))->name); |
20 | } |
21 | |
22 | return $this->hasOne(RefreshToken::class, 'token_id', 'id'); |
23 | } |
24 | } |