AbstractRefreshToken::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the GesdinetJWTRefreshTokenBundle package.
5
 *
6
 * (c) Gesdinet <http://www.gesdinet.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gesdinet\JWTRefreshTokenBundle\Entity;
13
14
use Symfony\Component\Validator\Constraints as Assert;
15
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
16
17
/**
18
 * Abstract Refresh Token.
19
 */
20 View Code Duplication
abstract class AbstractRefreshToken implements RefreshTokenInterface
0 ignored issues
show
Duplication introduced by
This class 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...
21
{
22
    /**
23
     * @var string
24
     *
25
     * @Assert\NotBlank()
26
     */
27
    private $refreshToken;
28
29
    /**
30
     * @var string
31
     *
32
     * @Assert\NotBlank()
33
     */
34
    private $username;
35
36
    /**
37
     * @var \DateTime
38
     *
39
     * @Assert\NotBlank()
40
     */
41
    private $valid;
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    abstract public function getId();
47
48
    /**
49
     * Set refreshToken.
50
     *
51
     * @param string $refreshToken
52
     *
53
     * @return AbstractRefreshToken
54
     */
55
    public function setRefreshToken($refreshToken = null)
56
    {
57
        $this->refreshToken = null === $refreshToken
58
            ? bin2hex(openssl_random_pseudo_bytes(64))
59
            : $refreshToken;
60
61
        return $this;
62
    }
63
64
    /**
65
     * Get refreshToken.
66
     *
67
     * @return string
68
     */
69
    public function getRefreshToken()
70
    {
71
        return $this->refreshToken;
72
    }
73
74
    /**
75
     * Set valid.
76
     *
77
     * @param \DateTime $valid
78
     *
79
     * @return AbstractRefreshToken
80
     */
81
    public function setValid($valid)
82
    {
83
        $this->valid = $valid;
84
85
        return $this;
86
    }
87
88
    /**
89
     * Get valid.
90
     *
91
     * @return \DateTime
92
     */
93
    public function getValid()
94
    {
95
        return $this->valid;
96
    }
97
98
    /**
99
     * Set username.
100
     *
101
     * @param string $username
102
     *
103
     * @return AbstractRefreshToken
104
     */
105
    public function setUsername($username)
106
    {
107
        $this->username = $username;
108
109
        return $this;
110
    }
111
112
    /**
113
     * Get username.
114
     *
115
     * @return string
116
     */
117
    public function getUsername()
118
    {
119
        return $this->username;
120
    }
121
122
    /**
123
     * Check if is a valid refresh token.
124
     *
125
     * @return bool
126
     */
127
    public function isValid()
128
    {
129
        return $this->valid >= new \DateTime();
130
    }
131
132
    /**
133
     * @return string Refresh Token
134
     */
135
    public function __toString()
136
    {
137
        return $this->getRefreshToken();
138
    }
139
}
140