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 |
||
| 21 | class Authentication extends AbstractMiddleware |
||
| 22 | { |
||
| 23 | |||
| 24 | use TranslationTrait; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var LoadUser |
||
| 28 | */ |
||
| 29 | private $loadUser; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param LoadUser $loadUser |
||
| 33 | */ |
||
| 34 | 4 | public function __construct(LoadUser $loadUser) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | 4 | public function processRequest(Request $request, Route $route) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @param Route $route |
||
| 71 | * @param UserVO $user |
||
| 72 | * @throws MethodNotAllowedException |
||
| 73 | */ |
||
| 74 | 4 | View Code Duplication | protected function checkForRole(Route $route, UserVO $user) : void |
| 83 | |||
| 84 | /** |
||
| 85 | * @param int $userId |
||
| 86 | * @return AnonymusUserVO|UserVO |
||
| 87 | */ |
||
| 88 | 4 | View Code Duplication | private function loadUser(int $userId) : UserVO |
| 99 | |||
| 100 | /** |
||
| 101 | * @param Request $request |
||
| 102 | * @return RedirectResponse |
||
| 103 | * @throws UserException |
||
| 104 | */ |
||
| 105 | 1 | private function handleNotAuthenticatedRequest(Request $request) : RedirectResponse |
|
| 113 | } |
||
| 114 |