AbstractRefreshToken::setRefreshToken()   A
last analyzed

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