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 |
||
| 25 | class FluentClient extends AbstractFluentAdapter implements ClientInterface |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Limit clients to grants. |
||
| 29 | * |
||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | protected $limitClientsToGrants = false; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Create a new fluent client instance. |
||
| 36 | * |
||
| 37 | * @param \Illuminate\Database\ConnectionResolverInterface $resolver |
||
| 38 | * @param bool $limitClientsToGrants |
||
| 39 | */ |
||
| 40 | 27 | public function __construct(Resolver $resolver, $limitClientsToGrants = false) |
|
| 41 | { |
||
| 42 | 27 | parent::__construct($resolver); |
|
| 43 | 27 | $this->limitClientsToGrants = $limitClientsToGrants; |
|
| 44 | 27 | } |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Check if clients are limited to grants. |
||
| 48 | * |
||
| 49 | * @return bool |
||
| 50 | */ |
||
| 51 | 6 | public function areClientsLimitedToGrants() |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Whether or not to limit clients to grants. |
||
| 58 | * |
||
| 59 | * @param bool $limit |
||
| 60 | */ |
||
| 61 | 6 | public function limitClientsToGrants($limit = false) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Get the client. |
||
| 68 | * |
||
| 69 | * @param string $clientId |
||
| 70 | * @param string $clientSecret |
||
|
|
|||
| 71 | * @param string $redirectUri |
||
| 72 | * @param string $grantType |
||
| 73 | * |
||
| 74 | * @return null|\League\OAuth2\Server\Entity\ClientEntity |
||
| 75 | */ |
||
| 76 | 21 | public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) |
|
| 136 | |||
| 137 | /** |
||
| 138 | * Get the client associated with a session. |
||
| 139 | * |
||
| 140 | * @param \League\OAuth2\Server\Entity\SessionEntity $session The session |
||
| 141 | * |
||
| 142 | * @return null|\League\OAuth2\Server\Entity\ClientEntity |
||
| 143 | */ |
||
| 144 | 6 | public function getBySession(SessionEntity $session) |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Create a new client. |
||
| 164 | * |
||
| 165 | * @param string $name The client's unique name |
||
| 166 | * @param string $id The client's unique id |
||
| 167 | * @param string $secret The clients' unique secret |
||
| 168 | * |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | public function create($name, $id, $secret) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Hydrate the entity. |
||
| 184 | * |
||
| 185 | * @param $result |
||
| 186 | * |
||
| 187 | * @return \League\OAuth2\Server\Entity\ClientEntity |
||
| 188 | */ |
||
| 189 | 18 | protected function hydrateEntity($result) |
|
| 201 | } |
||
| 202 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.