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 |
||
23 | View Code Duplication | abstract class AbstractRefreshToken implements RefreshTokenInterface |
|
|
|||
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) |
||
66 | |||
67 | /** |
||
68 | * Get refreshToken. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getRefreshToken() |
||
76 | |||
77 | /** |
||
78 | * Set valid. |
||
79 | * |
||
80 | * @param \DateTime $valid |
||
81 | * |
||
82 | * @return AbstractRefreshToken |
||
83 | */ |
||
84 | public function setValid($valid) |
||
90 | |||
91 | /** |
||
92 | * Get valid. |
||
93 | * |
||
94 | * @return \DateTime |
||
95 | */ |
||
96 | public function getValid() |
||
100 | |||
101 | /** |
||
102 | * Set username. |
||
103 | * |
||
104 | * @param string $username |
||
105 | * |
||
106 | * @return AbstractRefreshToken |
||
107 | */ |
||
108 | public function setUsername($username) |
||
114 | |||
115 | /** |
||
116 | * Get username. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getUsername() |
||
124 | |||
125 | /** |
||
126 | * Check if is a valid refresh token. |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function isValid() |
||
134 | |||
135 | /** |
||
136 | * @return string Refresh Token |
||
137 | */ |
||
138 | public function __toString() |
||
142 | } |
||
143 |
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.