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 |
||
| 18 | class JWTAuthenticationHandler implements AuthenticationHandler |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var JWTAuthenticator |
||
| 23 | */ |
||
| 24 | protected $authenticator; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @return mixed |
||
| 28 | */ |
||
| 29 | public function getAuthenticator() |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param mixed $authenticator |
||
| 36 | */ |
||
| 37 | public function setAuthenticator($authenticator) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param HTTPRequest $request |
||
| 44 | * @return null|Member |
||
| 45 | */ |
||
| 46 | public function authenticateRequest(HTTPRequest $request) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param Member $member |
||
| 65 | * @param bool $persistent |
||
| 66 | * @param HTTPRequest|null $request |
||
| 67 | */ |
||
| 68 | public function logIn(Member $member, $persistent = false, HTTPRequest $request = null) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param HTTPRequest|null $request |
||
| 75 | */ |
||
| 76 | public function logOut(HTTPRequest $request = null) |
||
| 84 | } |
||
| 85 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.