Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WithRefreshable
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 refreshToken
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Albet\SanctumRefresh\Traits;
4
5use Albet\SanctumRefresh\Exceptions\InvalidModelException;
6use Albet\SanctumRefresh\Models\RefreshToken;
7use Illuminate\Database\Eloquent\Model;
8use Illuminate\Database\Eloquent\Relations\HasOne;
9use ReflectionClass;
10
11trait 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}