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 |
||
30 | class OAuthClient extends AbstractServiceClient |
||
31 | { |
||
32 | /* |
||
33 | * Authentication types constants |
||
34 | * |
||
35 | * The "code" type means that the application will use an intermediate code to obtain an access token. |
||
36 | * The "token" type will result a user is redirected back to the application with an access token in a URL |
||
37 | */ |
||
38 | const CODE_AUTH_TYPE = 'code'; |
||
39 | const TOKEN_AUTH_TYPE = 'token'; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $clientId = ''; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | private $clientSecret = ''; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | private $refreshToken = ''; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | 25 | protected $serviceDomain = 'oauth.yandex.ru'; |
|
60 | |||
61 | 25 | /** |
|
62 | 25 | * @param string $clientId |
|
63 | 25 | * @param string $clientSecret |
|
64 | */ |
||
65 | public function __construct($clientId = '', $clientSecret = '') |
||
70 | 25 | ||
71 | /** |
||
72 | 25 | * @param string $clientId |
|
73 | * |
||
74 | 25 | * @return self |
|
75 | */ |
||
76 | public function setClientId($clientId) |
||
82 | 2 | ||
83 | |||
84 | /** |
||
85 | * @param string $refreshToken |
||
86 | * |
||
87 | * @return self |
||
88 | */ |
||
89 | public function setRefreshToken($refreshToken) |
||
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getClientId() |
||
103 | |||
104 | /** |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getRefreshToken() |
||
111 | 2 | ||
112 | /** |
||
113 | 2 | * @param string $clientSecret |
|
114 | 2 | * |
|
115 | 1 | * @return self |
|
116 | 1 | */ |
|
117 | public function setClientSecret($clientSecret) |
||
123 | |||
124 | /** |
||
125 | * @return string |
||
126 | */ |
||
127 | public function getClientSecret() |
||
131 | 1 | ||
132 | /** |
||
133 | 1 | * @param string $type |
|
134 | * @param string $state optional string |
||
|
|||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | public function getAuthUrl($type = self::CODE_AUTH_TYPE, $addtions = null) |
||
172 | |||
173 | 1 | /** |
|
174 | * Sends a redirect to the Yandex authentication page. |
||
175 | 1 | * |
|
176 | 1 | * @param bool $exit indicates whether to stop the PHP script immediately or not |
|
177 | 1 | * @param string $type a type of the authentication procedure |
|
178 | 1 | * @param string $state optional string |
|
179 | * @return bool|void |
||
180 | */ |
||
181 | public function authRedirect($exit = true, $type = self::CODE_AUTH_TYPE, $addtions = null) |
||
187 | 4 | ||
188 | 1 | /** |
|
189 | * Exchanges a temporary code for an access token. |
||
190 | * |
||
191 | 3 | * @param $code |
|
192 | 1 | * |
|
193 | * @return self |
||
194 | * @throws AuthResponseException on a response format error |
||
195 | 2 | * @throws RequestException on an unknown request error |
|
196 | 1 | * |
|
197 | * @throws AuthRequestException on a known request error |
||
198 | */ |
||
199 | 1 | View Code Duplication | public function requestAccessToken($code) |
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||
269 | |||
270 | View Code Duplication | public function refreshAccessToken(string $refreshToken) |
|
335 | |||
336 | } |
||
337 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.