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 |
||
| 19 | class TokenAuthentication extends AbstractMiddleware |
||
| 20 | { |
||
| 21 | use TranslationTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var LoadUser |
||
| 25 | */ |
||
| 26 | private $loadUser; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var Token |
||
| 30 | */ |
||
| 31 | private $token; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param LoadUser $loadUser |
||
| 35 | * @param Token $token |
||
| 36 | */ |
||
| 37 | 3 | public function __construct(LoadUser $loadUser, Token $token) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 3 | public function processRequest(Request $request, Route $route) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @todo check/implement |
||
|
|
|||
| 66 | * @param Route $route |
||
| 67 | * @param UserVO $user |
||
| 68 | * @throws MethodNotAllowedException |
||
| 69 | */ |
||
| 70 | View Code Duplication | protected function checkForRole(Route $route, UserVO $user) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @param int $userId |
||
| 82 | * @return AnonymusUserVO|UserVO |
||
| 83 | */ |
||
| 84 | 1 | View Code Duplication | private function loadUser(int $userId) : UserVO |
| 96 | } |
||
| 97 |
This check looks
TODOcomments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.