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) |
|
| 48 | |||
| 49 | /* |
||
| 50 | public function getByRefreshToken(RefreshTokenEntity $refreshToken) |
||
| 51 | { |
||
| 52 | $result = $this->getConnection()->table('oauth_access_tokens') |
||
| 53 | ->select('oauth_access_tokens.*') |
||
| 54 | ->join('oauth_refresh_tokens', 'oauth_access_tokens.id', '=', 'oauth_refresh_tokens.access_token_id') |
||
| 55 | ->where('oauth_refresh_tokens.id', $refreshToken->getId()) |
||
| 56 | ->first(); |
||
| 57 | |||
| 58 | if (is_null($result)) { |
||
| 59 | return null; |
||
| 60 | } |
||
| 61 | |||
| 62 | return (new AccessTokenEntity($this->getServer())) |
||
| 63 | ->setId($result->id) |
||
| 64 | ->setExpireTime((int)$result->expire_time); |
||
| 65 | } |
||
| 66 | */ |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Get the scopes for an access token. |
||
| 70 | * |
||
| 71 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token |
||
| 72 | * |
||
| 73 | * @return array Array of \League\OAuth2\Server\Entity\ScopeEntity |
||
| 74 | */ |
||
| 75 | 3 | View Code Duplication | public function getScopes(AccessTokenEntity $token) |
| 95 | |||
| 96 | /** |
||
| 97 | * Creates a new access token. |
||
| 98 | * |
||
| 99 | * @param string $token The access token |
||
| 100 | * @param int $expireTime The expire time expressed as a unix timestamp |
||
| 101 | * @param string|int $sessionId The session ID |
||
| 102 | * |
||
| 103 | * @return \League\OAuth2\Server\Entity\AccessTokenEntity |
||
| 104 | */ |
||
| 105 | 3 | View Code Duplication | public function create($token, $expireTime, $sessionId) |
| 119 | |||
| 120 | /** |
||
| 121 | * Associate a scope with an access token. |
||
| 122 | * |
||
| 123 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token |
||
| 124 | * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope |
||
| 125 | * |
||
| 126 | * @return void |
||
| 127 | */ |
||
| 128 | 3 | View Code Duplication | public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) |
| 137 | |||
| 138 | /** |
||
| 139 | * Delete an access token. |
||
| 140 | * |
||
| 141 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete |
||
| 142 | * |
||
| 143 | * @return void |
||
| 144 | */ |
||
| 145 | 3 | public function delete(AccessTokenEntity $token) |
|
| 151 | } |
||
| 152 |
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.