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 | class OAuthPasswordAuthentication extends AbstractAuthentication |
||
24 | { |
||
25 | const AUTHENTICATION_GRANT_TYPE = 'password'; |
||
26 | |||
27 | /** |
||
28 | * Username for OAuth password authentication. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $username; |
||
33 | |||
34 | /** |
||
35 | * Password for OAuth password authentication. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $password; |
||
40 | |||
41 | /** |
||
42 | * Gets the value of username. |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getUsername() |
||
50 | |||
51 | /** |
||
52 | * Sets the value of username. |
||
53 | * |
||
54 | * @param string $username Value to set |
||
55 | * |
||
56 | * @return self |
||
57 | */ |
||
58 | public function setUsername($username) |
||
64 | |||
65 | /** |
||
66 | * Gets the value of password. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getPassword() |
||
74 | |||
75 | /** |
||
76 | * Sets the value of password. |
||
77 | * |
||
78 | * @param string $password Value to set |
||
79 | * |
||
80 | * @return self |
||
81 | */ |
||
82 | public function setPassword($password) |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | View Code Duplication | public function refreshAccessToken() |
|
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | View Code Duplication | public function getAuthenticationTokens() |
|
164 | } |
||
165 |
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.