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 |
||
| 22 | final class AccessTokenApi |
||
| 23 | { |
||
| 24 | const URL = 'access-tokens/'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Immediately expires the access tokens passed. |
||
| 28 | * |
||
| 29 | * More info: https://api.stackexchange.com/docs/invalidate-access-tokens |
||
| 30 | * |
||
| 31 | * @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token |
||
| 32 | * @param array $params QueryString parameter(s), it admits page and pagesize; by default is null |
||
| 33 | * @param bool $serialize Checks if the result will be serialize or not, by default is true |
||
| 34 | * |
||
| 35 | * @return array |
||
|
|
|||
| 36 | */ |
||
| 37 | View Code Duplication | public function invalidate($accessTokens, array $params = [], $serialize = true) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Reads the properties for a set of access tokens. |
||
| 48 | * |
||
| 49 | * More info: https://api.stackexchange.com/docs/read-access-tokens |
||
| 50 | * |
||
| 51 | * @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token |
||
| 52 | * @param array $params QueryString parameter(s), it admits page and pagesize; by default is null |
||
| 53 | * @param bool $serialize Checks if the result will be serialize or not, by default is true |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | public function getOfToken($accessTokens, array $params = [], $serialize = true) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Allows an application to de-authorize itself for a set of users. |
||
| 68 | * |
||
| 69 | * More info: https://api.stackexchange.com/docs/application-de-authenticate |
||
| 70 | * |
||
| 71 | * @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token |
||
| 72 | * @param array $params QueryString parameter(s), it admits page and pagesize; by default is null |
||
| 73 | * @param bool $serialize Checks if the result will be serialize or not, by default is true |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function deAuthenticate($accessTokens, array $params = [], $serialize = true) |
||
| 85 | } |
||
| 86 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]orarray<String>.