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 | * "@Core.Authentication.LoadUser", |
||
40 | * "@Core.Authentication.Token", |
||
41 | * }) |
||
42 | * @param LoadUser $loadUser |
||
43 | * @param Token $token |
||
44 | */ |
||
45 | 4 | public function __construct(LoadUser $loadUser, Token $token) |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 3 | public function processRequest(Request $request, Route $route) |
|
71 | |||
72 | /** |
||
73 | * @todo check/implement |
||
|
|||
74 | * @param Route $route |
||
75 | * @param UserVO $user |
||
76 | * @throws MethodNotAllowedException |
||
77 | */ |
||
78 | View Code Duplication | protected function checkForRole(Route $route, UserVO $user) |
|
87 | |||
88 | /** |
||
89 | * @param int $userId |
||
90 | * @return AnonymusUserVO|UserVO |
||
91 | */ |
||
92 | 1 | View Code Duplication | private function loadUser(int $userId) : UserVO |
104 | } |
||
105 |
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.