Conditions | 9 |
Paths | 13 |
Total Lines | 68 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
46 | public function userSettings(Request $request, UserPasswordHasherInterface $passwordEncoder, EntityManagerInterface $entityManager, |
||
47 | GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager): Response |
||
48 | { |
||
49 | $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); |
||
50 | |||
51 | $user = $this->getUser(); |
||
52 | if (!$user instanceof User) { |
||
53 | throw new RuntimeException('This controller can only manage App\Entity\User objects!'); |
||
54 | } |
||
55 | |||
56 | $pw_form = $this->createForm(PasswordChangeType::class); |
||
57 | $pw_form->handleRequest($request); |
||
58 | |||
59 | if ($pw_form->isSubmitted() && $pw_form->isValid()) { |
||
60 | //If form is valid, the old password was already validated, so we just have to encrypt the pw now |
||
61 | $hashed_pw = $passwordEncoder->hashPassword($user, $pw_form['plain_password']->getData()); |
||
62 | $user->setPassword($hashed_pw); |
||
63 | $user->setPasswordChangeNeeded(false); |
||
64 | |||
65 | $entityManager->flush(); |
||
66 | |||
67 | $this->addFlash('success', 'password.changed_successful'); |
||
68 | } |
||
69 | |||
70 | //Handle 2FA things |
||
71 | $google_form = $this->createForm(TFAGoogleSettingsType::class, $user); |
||
72 | $google_enabled = $user->isGoogleAuthenticatorEnabled(); |
||
73 | if (!$google_enabled && !$google_form->isSubmitted()) { |
||
74 | $user->setGoogleAuthenticatorSecret($googleAuthenticator->generateSecret()); |
||
75 | $google_form->get('googleAuthenticatorSecret') |
||
76 | ->setData($user->getGoogleAuthenticatorSecret()); |
||
77 | } |
||
78 | $google_form->handleRequest($request); |
||
79 | |||
80 | if ($google_form->isSubmitted() && $google_form->isValid()) { |
||
81 | if (!$google_enabled) { |
||
82 | //Save 2FA settings (save secrets) |
||
83 | $user->setGoogleAuthenticatorSecret($google_form->get('googleAuthenticatorSecret')->getData()); |
||
84 | $backupCodeManager->enableBackupCodes($user); |
||
85 | |||
86 | $entityManager->flush(); |
||
87 | $this->addFlash('success', 'user.settings.2fa.google.activated'); |
||
88 | |||
89 | return $this->redirect($request->getUri()); |
||
90 | } |
||
91 | |||
92 | //Remove secret to disable google authenticator |
||
93 | $user->setGoogleAuthenticatorSecret(null); |
||
94 | $backupCodeManager->disableBackupCodesIfUnused($user); |
||
95 | $entityManager->flush(); |
||
96 | $this->addFlash('success', 'user.settings.2fa.google.disabled'); |
||
97 | |||
98 | return $this->redirect($request->getUri()); |
||
99 | } |
||
100 | |||
101 | |||
102 | $qrCode = QrCode::create($googleAuthenticator->getQRContent($user)); |
||
103 | |||
104 | return $this->render('admin/user/settings.html.twig', [ |
||
105 | 'user' => $user, |
||
106 | 'pw_form' => $pw_form->createView(), |
||
107 | 'google_form' => $google_form->createView(), |
||
108 | 'tfa_google' => [ |
||
109 | 'enabled' => $google_enabled, |
||
110 | 'qrContent' => $googleAuthenticator->getQRContent($user), |
||
111 | 'secret' => $user->getGoogleAuthenticatorSecret(), |
||
112 | 'qrImageDataUri' => (new SvgWriter())->write($qrCode)->getDataUri(), |
||
113 | 'username' => $user->getGoogleAuthenticatorUsername(), |
||
114 | ], |
||
195 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths