Completed
Push — master ( 88b001...24ab37 )
by Derek Stephen
10:51
created

RefreshToken   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 245
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 0
dl 245
loc 245
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 4 4 1
A setRefreshToken() 5 5 1
A getRefreshToken() 4 4 1
A setClientId() 5 5 1
A getClientId() 4 4 1
A setUserId() 5 5 1
A getUserId() 4 4 1
A setExpires() 5 5 1
A getExpires() 4 4 1
A setScope() 5 5 1
A getScope() 4 4 1
A setClient() 5 5 1
A getClient() 4 4 1
A setUser() 5 5 1
A getUser() 4 4 1
A toArray() 10 10 1
A fromArray() 8 8 2

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 OAuth;
4
5
use DateTime;
6
7
/**
8
 * @Entity(repositoryClass="OAuth\Repository\RefreshTokenRepository")
9
 * @Table(name="RefreshToken",uniqueConstraints={@UniqueConstraint(name="refresh_token_idx", columns={"refreshToken"})})
10
 */
11 View Code Duplication
class RefreshToken
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...
12
{
13
    /**
14
     * @var integer
15
     * @Id
16
     * @Column(type="integer", length=11)
17
     * @GeneratedValue
18
     */
19
    private $id;
20
21
    /**
22
     * @var string
23
     * @Column(type="string",length=40)
24
     */
25
    private $refreshToken;
26
27
    /**
28
     * @var int
29
     * @Column(type="integer",length=11)
30
     */
31
    private $clientId;
32
33
    /**
34
     * @var int
35
     * @Column(type="integer",length=11, nullable=true)
36
     */
37
    private $userId;
38
39
    /**
40
     * @var DateTime
41
     * @Column(type="datetime")
42
     */
43
    private $expires;
44
45
    /**
46
     * @var string
47
     * @Column(type="string",length=50)
48
     */
49
    private $scope;
50
51
    /**
52
     * @var Client
53
     * @ManyToOne(targetEntity="OAuth\Client")
54
     * @JoinColumn(name="client", referencedColumnName="id")
55
     */
56
    private $client;
57
58
    /**
59
     * @var User
60
     * @ManyToOne(targetEntity="OAuth\User")
61
     * @JoinColumn(name="user", referencedColumnName="id")
62
     */
63
    private $user;
64
65
    /**
66
     * Get id
67
     *
68
     * @return integer
69
     */
70
    public function getId()
71
    {
72
        return $this->id;
73
    }
74
75
    /**
76
     * Set refresh_token
77
     *
78
     * @param string $refresh_token
79
     * @return RefreshToken
80
     */
81
    public function setRefreshToken($refresh_token)
82
    {
83
        $this->refresh_token = $refresh_token;
0 ignored issues
show
Bug introduced by
The property refresh_token does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
84
        return $this;
85
    }
86
87
    /**
88
     * Get refresh_token
89
     *
90
     * @return string
91
     */
92
    public function getRefreshToken()
93
    {
94
        return $this->refreshToken;
95
    }
96
97
    /**
98
     * Set client_id
99
     *
100
     * @param int $clientId
101
     * @return RefreshToken
102
     */
103
    public function setClientId($clientId)
104
    {
105
        $this->clientId = $clientId;
106
        return $this;
107
    }
108
109
    /**
110
     * Get client_id
111
     *
112
     * @return int
113
     */
114
    public function getClientId()
115
    {
116
        return $this->clientId;
117
    }
118
119
    /**
120
     * Set user_id
121
     *
122
     * @param int $userId
123
     * @return RefreshToken
124
     */
125
    public function setUserId($userId)
126
    {
127
        $this->userId = $userId;
128
        return $this;
129
    }
130
131
    /**
132
     * Get user_identifier
133
     *
134
     * @return int
135
     */
136
    public function getUserId()
137
    {
138
        return $this->userId;
139
    }
140
141
    /**
142
     * Set expires
143
     *
144
     * @param DateTime $expires
145
     * @return RefreshToken
146
     */
147
    public function setExpires(DateTime $expires)
148
    {
149
        $this->expires = $expires;
150
        return $this;
151
    }
152
153
    /**
154
     * Get expires
155
     *
156
     * @return DateTime
157
     */
158
    public function getExpires()
159
    {
160
        return $this->expires;
161
    }
162
163
    /**
164
     * Set scope
165
     *
166
     * @param string $scope
167
     * @return RefreshToken
168
     */
169
    public function setScope($scope)
170
    {
171
        $this->scope = $scope;
172
        return $this;
173
    }
174
175
    /**
176
     * Get scope
177
     *
178
     * @return string
179
     */
180
    public function getScope()
181
    {
182
        return $this->scope;
183
    }
184
185
    /**
186
     * Set client
187
     *
188
     * @param Client $client
189
     * @return RefreshToken
190
     */
191
    public function setClient(Client $client = null)
192
    {
193
        $this->client = $client;
194
        return $this;
195
    }
196
197
    /**
198
     * Get client
199
     *
200
     * @return Client
201
     */
202
    public function getClient()
203
    {
204
        return $this->client;
205
    }
206
207
    /**
208
     * Set user
209
     *
210
     * @param User $user
211
     * @return RefreshToken
212
     */
213
    public function setUser(User $user = null)
214
    {
215
        $this->user = $user;
216
        return $this;
217
    }
218
219
    /**
220
     * Get user
221
     *
222
     * @return User
223
     */
224
    public function getUser()
225
    {
226
        return $this->user;
227
    }
228
229
    /**
230
     * @return array
231
     */
232
    public function toArray()
233
    {
234
        return [
235
            'refresh_token' => $this->refreshToken,
236
            'client_id' => $this->clientId,
237
            'user_id' => $this->userId,
238
            'expires' => $this->expires,
239
            'scope' => $this->scope,
240
        ];
241
    }
242
243
    /**
244
     * @param $params
245
     * @return RefreshToken
246
     */
247
    public static function fromArray($params)
248
    {
249
        $token = new self();
250
        foreach ($params as $property => $value) {
251
            $token->$property = $value;
252
        }
253
        return $token;
254
    }
255
}