1515use CodeFareith \CfGoogleAuthenticator \Domain \Form \SetupForm ;
1616use CodeFareith \CfGoogleAuthenticator \Domain \Immutable \AuthenticationSecret ;
1717use CodeFareith \CfGoogleAuthenticator \Domain \Model \FrontendUser ;
18+ use CodeFareith \CfGoogleAuthenticator \Domain \Repository \FrontendUserRepository ;
1819use CodeFareith \CfGoogleAuthenticator \Service \GoogleQrCodeGenerator ;
1920use CodeFareith \CfGoogleAuthenticator \Service \QrCodeGeneratorInterface ;
20- use CodeFareith \CfGoogleAuthenticator \Traits \GeneralUtilityContext ;
2121use CodeFareith \CfGoogleAuthenticator \Utility \Base32Utility ;
2222use CodeFareith \CfGoogleAuthenticator \Utility \PathUtility ;
2323use CodeFareith \CfGoogleAuthenticator \Validation \Validator \SetupFormValidator ;
24+ use Exception ;
2425use TYPO3 \CMS \Core \Messaging \FlashMessage ;
25- use TYPO3 \CMS \Extbase \Domain \Repository \FrontendUserRepository ;
2626use TYPO3 \CMS \Extbase \Mvc \Controller \ActionController ;
2727use TYPO3 \CMS \Extbase \Mvc \Exception \NoSuchArgumentException ;
28+ use TYPO3 \CMS \Extbase \Mvc \Exception \StopActionException ;
29+ use TYPO3 \CMS \Extbase \Mvc \Exception \UnsupportedRequestTypeException ;
30+ use TYPO3 \CMS \Extbase \Object \InvalidClassException ;
31+ use TYPO3 \CMS \Extbase \Persistence \Exception \IllegalObjectTypeException ;
32+ use TYPO3 \CMS \Extbase \Persistence \Exception \UnknownObjectException ;
2833use TYPO3 \CMS \Lang \LanguageService ;
2934
3035/**
@@ -50,6 +55,9 @@ class SetupController
5055 /** @var SetupFormValidator */
5156 protected $ setupFormValidator ;
5257
58+ /** @var LanguageService */
59+ protected $ languageService ;
60+
5361 /** @var AuthenticationSecret */
5462 private $ authenticationSecret ;
5563
@@ -59,18 +67,20 @@ class SetupController
5967 public function __construct (
6068 FrontendUserRepository $ frontendUserRepository ,
6169 GoogleQrCodeGenerator $ qrCodeGenerator ,
62- SetupFormValidator $ setupFormValidator
70+ SetupFormValidator $ setupFormValidator ,
71+ LanguageService $ languageService
6372 )
6473 {
6574 parent ::__construct ();
6675
6776 $ this ->frontendUserRepository = $ frontendUserRepository ;
6877 $ this ->qrCodeGenerator = $ qrCodeGenerator ;
6978 $ this ->setupFormValidator = $ setupFormValidator ;
79+ $ this ->languageService = $ languageService ;
7080 }
7181
7282 /**
73- * @throws \ Exception
83+ * @throws Exception
7484 */
7585 public function indexAction (): void
7686 {
@@ -107,10 +117,10 @@ public function initializeUpdateAction(): void
107117
108118 /**
109119 * @throws NoSuchArgumentException
110- * @throws \TYPO3\CMS\Extbase\Mvc\Exception\ StopActionException
111- * @throws \TYPO3\CMS\Extbase\Persistence\Exception\ IllegalObjectTypeException
112- * @throws \TYPO3\CMS\Extbase\Persistence\Exception\ UnknownObjectException
113- * @throws \TYPO3\CMS\Extbase\Mvc\Exception\ UnsupportedRequestTypeException
120+ * @throws StopActionException
121+ * @throws IllegalObjectTypeException
122+ * @throws UnknownObjectException
123+ * @throws UnsupportedRequestTypeException
114124 */
115125 public function updateAction (): void
116126 {
@@ -155,7 +165,7 @@ private function isUserLoggedin(): bool
155165 }
156166
157167 /**
158- * @throws \ Exception
168+ * @throws Exception
159169 */
160170 private function getAuthenticationSecret (): AuthenticationSecret
161171 {
@@ -195,7 +205,7 @@ private function getUsername(): string
195205 }
196206
197207 /**
198- * @throws \ Exception
208+ * @throws Exception
199209 */
200210 private function getSecretKey (): string
201211 {
@@ -226,16 +236,30 @@ private function isGoogleAuthenticatorEnabled(): bool
226236 }
227237
228238 /**
229- * @throws \ Exception
239+ * @throws Exception
230240 */
231241 private function getSetupForm (): SetupForm
232242 {
233243 /** @noinspection PhpMethodParametersCountMismatchInspection */
234- return $ this ->objectManager ->get (
244+ $ object = $ this ->objectManager ->get (
235245 SetupForm::class,
236246 $ this ->getAuthenticationSecret ()->getSecretKey (),
237247 ''
238248 );
249+
250+ if (!$ object instanceof SetupForm) {
251+ throw new InvalidClassException (
252+ \vsprintf (
253+ 'Invalid class. Expected "%s", got "%s". ' ,
254+ [
255+ SetupForm::class,
256+ \get_class ($ object ),
257+ ]
258+ )
259+ );
260+ }
261+
262+ return $ object ;
239263 }
240264
241265 /**
@@ -274,6 +298,6 @@ private function getFrontendUserId(): int
274298
275299 private function getLanguageService (): LanguageService
276300 {
277- return $ GLOBALS [ ' LANG ' ] ;
301+ return $ this -> languageService ;
278302 }
279303}
0 commit comments