AccessTokenVoidStorage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 20.59 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 14
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasToken() 0 4 1
A getToken() 0 8 2
A setToken() 0 4 1
A abandonToken() 0 4 1
A isTokenExpired() 14 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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