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 | * Pre-register redirect url is required. |
||
35 | * |
||
36 | * @var bool |
||
37 | */ |
||
38 | protected $limitRedirectUri = false; |
||
39 | /** |
||
40 | * Create a new fluent client instance. |
||
41 | * |
||
42 | * @param \Illuminate\Database\ConnectionResolverInterface $resolver |
||
43 | * @param bool $limitClientsToGrants |
||
44 | * @param bool $limitRedirectUri |
||
45 | */ |
||
46 | 24 | public function __construct(Resolver $resolver, $limitClientsToGrants = false, $limitRedirectUri = false) |
|
52 | |||
53 | /** |
||
54 | * Check if clients are limited to grants. |
||
55 | * |
||
56 | * @return bool |
||
57 | */ |
||
58 | 6 | public function areClientsLimitedToGrants() |
|
62 | |||
63 | /** |
||
64 | * Whether or not to limit clients to grants. |
||
65 | * |
||
66 | * @param bool $limit |
||
67 | */ |
||
68 | 6 | public function limitClientsToGrants($limit = false) |
|
72 | |||
73 | /** |
||
74 | * Get the client. |
||
75 | * |
||
76 | * @param string $clientId |
||
77 | * @param string $clientSecret |
||
|
|||
78 | * @param string $redirectUri |
||
79 | * @param string $grantType |
||
80 | * |
||
81 | * @return null|\League\OAuth2\Server\Entity\ClientEntity |
||
82 | */ |
||
83 | 18 | public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) |
|
153 | |||
154 | /** |
||
155 | * Get the client associated with a session. |
||
156 | * |
||
157 | * @param \League\OAuth2\Server\Entity\SessionEntity $session The session |
||
158 | * |
||
159 | * @return null|\League\OAuth2\Server\Entity\ClientEntity |
||
160 | */ |
||
161 | 6 | public function getBySession(SessionEntity $session) |
|
178 | |||
179 | /** |
||
180 | * Create a new client. |
||
181 | * |
||
182 | * @param string $name The client's unique name |
||
183 | * @param string $id The client's unique id |
||
184 | * @param string $secret The clients' unique secret |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function create($name, $id, $secret) |
||
198 | |||
199 | /** |
||
200 | * Hydrate the entity. |
||
201 | * |
||
202 | * @param $result |
||
203 | * |
||
204 | * @return \League\OAuth2\Server\Entity\ClientEntity |
||
205 | */ |
||
206 | 15 | protected function hydrateEntity($result) |
|
218 | } |
||
219 |
This check looks for
@param
annotations 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.