AccessTokenVoidStorage::getToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Fousky\Component\iDoklad\Storage;
4
5
use Fousky\Component\iDoklad\Exception\TokenNotFoundException;
6
use Fousky\Component\iDoklad\Model\Auth\AccessToken;
7
8
/**
9
 * @author Lukáš Brzák <[email protected]>
10
 */
11
class AccessTokenVoidStorage implements AccessTokenStorageInterface
12
{
13
    protected $token;
14
15
    /**
16
     * Has storage token?
17
     *
18
     * @return bool
19
     */
20
    public function hasToken(): bool
21
    {
22
        return null !== $this->token;
23
    }
24
25
    /**
26
     * Get AccessToken from Storage or throw TokenNotFoundException if not found.
27
     *
28
     * @throws TokenNotFoundException
29
     *
30
     * @return AccessToken
31
     */
32
    public function getToken(): AccessToken
33
    {
34
        if ($this->hasToken()) {
35
            return $this->token;
36
        }
37
38
        throw new TokenNotFoundException();
39
    }
40
41
    /**
42
     * Set AccessToken to the Storage object.
43
     *
44
     * @param AccessToken $token
45
     */
46
    public function setToken(AccessToken $token)
47
    {
48
        $this->token = $token;
49
    }
50
51
    /**
52
     * Abandon AccessToken.
53
     */
54
    public function abandonToken()
55
    {
56
        $this->token = null;
57
    }
58
59
    /**
60
     * Is AccessToken expired?
61
     *
62
     * @return bool
63
     */
64 View Code Duplication
    public function isTokenExpired(): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        try {
67
            $token = $this->getToken();
68
69
            if (!$token instanceof AccessToken) {
70
                return true;
71
            }
72
73
            return $token->isExpired();
74
        } catch (\Throwable $e) {
75
            return true;
76
        }
77
    }
78
}
79