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 |
||
| 24 | class FluentAuthCode extends AbstractFluentAdapter implements AuthCodeInterface |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Get the auth code. |
||
| 28 | * |
||
| 29 | * @param string $code |
||
| 30 | * |
||
| 31 | * @return \League\OAuth2\Server\Entity\AuthCodeEntity |
||
|
|
|||
| 32 | */ |
||
| 33 | 12 | View Code Duplication | public function get($code) |
| 49 | |||
| 50 | /** |
||
| 51 | * Get the scopes for an access token. |
||
| 52 | * |
||
| 53 | * @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code |
||
| 54 | * |
||
| 55 | * @return array Array of \League\OAuth2\Server\Entity\ScopeEntity |
||
| 56 | */ |
||
| 57 | 3 | View Code Duplication | public function getScopes(AuthCodeEntity $token) |
| 76 | |||
| 77 | /** |
||
| 78 | * Associate a scope with an access token. |
||
| 79 | * |
||
| 80 | * @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code |
||
| 81 | * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope |
||
| 82 | * |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | 3 | View Code Duplication | public function associateScope(AuthCodeEntity $token, ScopeEntity $scope) |
| 94 | |||
| 95 | /** |
||
| 96 | * Delete an access token. |
||
| 97 | * |
||
| 98 | * @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The access token to delete |
||
| 99 | * |
||
| 100 | * @return void |
||
| 101 | */ |
||
| 102 | 3 | public function delete(AuthCodeEntity $token) |
|
| 103 | { |
||
| 104 | 3 | $this->getConnection()->table('oauth_auth_codes') |
|
| 105 | 3 | ->where('oauth_auth_codes.id', $token->getId()) |
|
| 106 | 3 | ->delete(); |
|
| 107 | 3 | } |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Create an auth code. |
||
| 111 | * |
||
| 112 | * @param string $token The token ID |
||
| 113 | * @param int $expireTime Token expire time |
||
| 114 | * @param int $sessionId Session identifier |
||
| 115 | * @param string $redirectUri Client redirect uri |
||
| 116 | * |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | 3 | public function create($token, $expireTime, $sessionId, $redirectUri) |
|
| 130 | } |
||
| 131 |
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.