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 FluentAccessToken extends AbstractFluentAdapter implements AccessTokenInterface |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Get an instance of Entities\AccessToken. |
||
| 28 | * |
||
| 29 | * @param string $token The access token |
||
| 30 | * |
||
| 31 | * @return null|AbstractTokenEntity |
||
|
|
|||
| 32 | */ |
||
| 33 | 9 | public function get($token) |
|
| 47 | |||
| 48 | /* |
||
| 49 | public function getByRefreshToken(RefreshTokenEntity $refreshToken) |
||
| 50 | { |
||
| 51 | $result = $this->getConnection()->table('oauth_access_tokens') |
||
| 52 | ->select('oauth_access_tokens.*') |
||
| 53 | ->join('oauth_refresh_tokens', 'oauth_access_tokens.id', '=', 'oauth_refresh_tokens.access_token_id') |
||
| 54 | ->where('oauth_refresh_tokens.id', $refreshToken->getId()) |
||
| 55 | ->first(); |
||
| 56 | |||
| 57 | if (is_null($result)) { |
||
| 58 | return null; |
||
| 59 | } |
||
| 60 | |||
| 61 | return (new AccessTokenEntity($this->getServer())) |
||
| 62 | ->setId($result->id) |
||
| 63 | ->setExpireTime((int)$result->expire_time); |
||
| 64 | } |
||
| 65 | */ |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get the scopes for an access token. |
||
| 69 | * |
||
| 70 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token |
||
| 71 | * |
||
| 72 | * @return array Array of \League\OAuth2\Server\Entity\ScopeEntity |
||
| 73 | */ |
||
| 74 | 3 | View Code Duplication | public function getScopes(AccessTokenEntity $token) |
| 93 | |||
| 94 | /** |
||
| 95 | * Creates a new access token. |
||
| 96 | * |
||
| 97 | * @param string $token The access token |
||
| 98 | * @param int $expireTime The expire time expressed as a unix timestamp |
||
| 99 | * @param string|int $sessionId The session ID |
||
| 100 | * |
||
| 101 | * @return \League\OAuth2\Server\Entity\AccessTokenEntity |
||
| 102 | */ |
||
| 103 | 3 | View Code Duplication | public function create($token, $expireTime, $sessionId) |
| 117 | |||
| 118 | /** |
||
| 119 | * Associate a scope with an access token. |
||
| 120 | * |
||
| 121 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token |
||
| 122 | * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope |
||
| 123 | * |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | 3 | View Code Duplication | public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) |
| 135 | |||
| 136 | /** |
||
| 137 | * Delete an access token. |
||
| 138 | * |
||
| 139 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete |
||
| 140 | * |
||
| 141 | * @return void |
||
| 142 | */ |
||
| 143 | 3 | public function delete(AccessTokenEntity $token) |
|
| 149 | } |
||
| 150 |
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.