Passed
Push — main ( 69451c...874877 )
by Garbuz
03:25
created

UserTrait::tokensDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Garbuzivan\Laraveltokens\Traits;
6
7
use DateTime;
8
use Garbuzivan\Laraveltokens\Exceptions\UserNotExistsException;
9
use Garbuzivan\Laraveltokens\Models\AccessToken;
10
use Garbuzivan\Laraveltokens\Models\RefreshToken;
11
use Garbuzivan\Laraveltokens\TokenManager;
12
use Illuminate\Database\Eloquent\Relations\MorphMany;
13
14
trait UserTrait
15
{
16
    /**
17
     * @return MorphMany
18
     */
19
    public function accessTokens(): MorphMany
20
    {
21
        return $this->morphMany(AccessToken::class, 'userable');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        return $this->/** @scrutinizer ignore-call */ morphMany(AccessToken::class, 'userable');
Loading history...
22
    }
23
24
    /**
25
     * @return MorphMany
26
     */
27
    public function refreshTokens(): MorphMany
28
    {
29
        return $this->morphMany(RefreshToken::class, 'userable');
30
    }
31
32
    /**
33
     * Создать новый токен пользователя
34
     * @param string $title
35
     * @param DateTime|null $expiration
36
     * @return AccessToken
37
     * @throws UserNotExistsException
38
     */
39
    public function accessTokenCreate(string $title = '', ?DateTime $expiration = null): AccessToken
40
    {
41
        return app(TokenManager::class)->createAccessToken($title, $expiration, $this->id);
42
    }
43
44
    /**
45
     * Удалить все токены пользователя
46
     * @return bool
47
     */
48
    public function accessTokensDelete(): bool
49
    {
50
        return app(TokenManager::class)->deleteByUserAccessToken($this->id);
0 ignored issues
show
Bug introduced by
The method deleteByUserAccessToken() does not exist on Garbuzivan\Laraveltokens\TokenManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        return app(TokenManager::class)->/** @scrutinizer ignore-call */ deleteByUserAccessToken($this->id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
    }
52
}
53