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 |
||
| 26 | class FluentSession extends AbstractFluentAdapter implements SessionInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Get a session from it's identifier. |
||
| 30 | * |
||
| 31 | * @param string $sessionId |
||
| 32 | * |
||
| 33 | * @return \League\OAuth2\Server\Entity\SessionEntity |
||
|
|
|||
| 34 | */ |
||
| 35 | 6 | public function get($sessionId) |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Get a session from an access token. |
||
| 53 | * |
||
| 54 | * @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken The access token |
||
| 55 | * |
||
| 56 | * @return \League\OAuth2\Server\Entity\SessionEntity |
||
| 57 | */ |
||
| 58 | View Code Duplication | public function getByAccessToken(AccessTokenEntity $accessToken) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Get a session's scopes. |
||
| 78 | * |
||
| 79 | * @param \League\OAuth2\Server\Entity\SessionEntity |
||
| 80 | * |
||
| 81 | * @return array Array of \League\OAuth2\Server\Entity\ScopeEntity |
||
| 82 | */ |
||
| 83 | 3 | View Code Duplication | public function getScopes(SessionEntity $session) |
| 103 | |||
| 104 | /** |
||
| 105 | * Create a new session. |
||
| 106 | * |
||
| 107 | * @param string $ownerType Session owner's type (user, client) |
||
| 108 | * @param string $ownerId Session owner's ID |
||
| 109 | * @param string $clientId Client ID |
||
| 110 | * @param string $clientRedirectUri Client redirect URI (default = null) |
||
| 111 | * |
||
| 112 | * @return int The session's ID |
||
| 113 | */ |
||
| 114 | 3 | public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null) |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Associate a scope with a session. |
||
| 128 | * |
||
| 129 | * @param \League\OAuth2\Server\Entity\SessionEntity $session |
||
| 130 | * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scopes ID might be an integer or string |
||
| 131 | * |
||
| 132 | * @return void |
||
| 133 | */ |
||
| 134 | 3 | View Code Duplication | public function associateScope(SessionEntity $session, ScopeEntity $scope) |
| 143 | |||
| 144 | /** |
||
| 145 | * Get a session from an auth code. |
||
| 146 | * |
||
| 147 | * @param \League\OAuth2\Server\Entity\AuthCodeEntity $authCode The auth code |
||
| 148 | * |
||
| 149 | * @return \League\OAuth2\Server\Entity\SessionEntity |
||
| 150 | */ |
||
| 151 | 6 | View Code Duplication | public function getByAuthCode(AuthCodeEntity $authCode) |
| 168 | } |
||
| 169 |
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.