TokenRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 39
rs 10
ccs 17
cts 17
cp 1
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A retrieveAll() 0 3 1
A delete() 0 3 1
A retrieve() 0 7 2
A create() 0 9 2
A update() 0 7 1
1
<?php
2
3
namespace Bmatovu\AirtelMoney\Auth\Repositories;
4
5
use Bmatovu\AirtelMoney\Models\Token;
6
use Carbon\Carbon;
7
use Illuminate\Database\Eloquent\Model;
8
9
class TokenRepository implements TokenRepositoryInterface
10
{
11 6
    public function create(array $tokenAttrs): Model
12
    {
13 6
        $tokenAttrs['token_type'] = 'Bearer';
14
15 6
        if (isset($tokenAttrs['expires_in'])) {
16 6
            $tokenAttrs['expires_at'] = Carbon::now()->addSeconds($tokenAttrs['expires_in']);
17
        }
18
19 6
        return Token::create($tokenAttrs);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Bmatovu\AirtelMon...en::create($tokenAttrs) could return the type Illuminate\Database\Eloq...gHasThroughRelationship which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Model. Consider adding an additional type-check to rule them out.
Loading history...
20
    }
21
22 1
    public function retrieveAll()
23
    {
24 1
        return Token::get();
25
    }
26
27 8
    public function retrieve(?string $accessToken = null): ?Model
28
    {
29 8
        if ($accessToken) {
30 1
            return Token::where('access_token', $accessToken)->first();
31
        }
32
33 7
        return Token::latest('created_at')->first();
34
    }
35
36 1
    public function update(string $accessToken, array $tokenAttrs): Model
37
    {
38 1
        $token = Token::where('access_token', $accessToken)->firstOrFail();
39
40 1
        $token->update($tokenAttrs);
41
42 1
        return $token->fresh();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $token->fresh() could return the type null which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Model. Consider adding an additional type-check to rule them out.
Loading history...
43
    }
44
45 2
    public function delete(string $accessToken): void
46
    {
47 2
        Token::where('access_token', $accessToken)->delete();
48
    }
49
}
50