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 |
||
23 | class TokenAuthentication extends AbstractMiddleware |
||
24 | { |
||
25 | use TranslationTrait; |
||
26 | |||
27 | /** |
||
28 | * @var LoadUser |
||
29 | */ |
||
30 | private $loadUser; |
||
31 | |||
32 | /** |
||
33 | * @var Token |
||
34 | */ |
||
35 | private $token; |
||
36 | |||
37 | /** |
||
38 | * @Inject |
||
39 | * @param LoadUser $loadUser |
||
40 | * @param Token $token |
||
41 | */ |
||
42 | 4 | public function __construct(LoadUser $loadUser, Token $token) |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 3 | public function processRequest(Request $request, Route $route) |
|
68 | |||
69 | /** |
||
70 | * @todo check/implement |
||
|
|||
71 | * @param Route $route |
||
72 | * @param UserVO $user |
||
73 | * @throws MethodNotAllowedException |
||
74 | */ |
||
75 | View Code Duplication | protected function checkForRole(Route $route, UserVO $user) |
|
84 | |||
85 | /** |
||
86 | * @param int $userId |
||
87 | * @return AnonymusUserVO|UserVO |
||
88 | */ |
||
89 | 1 | View Code Duplication | private function loadUser(int $userId) : UserVO |
101 | } |
||
102 |
This check looks
TODO
comments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.