Completed
Pull Request — master (#139)
by
unknown
03:01
created

AbstractRefreshToken::setRefreshToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

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