1010namespace OxidEsales \SecurityModule \PasswordPolicy \Intrastructure ;
1111
1212use OxidEsales \Eshop \Core \Exception \InputException ;
13+ use OxidEsales \Eshop \Core \Language ;
1314use OxidEsales \SecurityModule \PasswordPolicy \Validation \Exception \PasswordCollectionException ;
1415use OxidEsales \SecurityModule \PasswordPolicy \Validation \Exception \PasswordValidateException ;
1516
16- class ExceptionFactory implements ExceptionFactoryInterface
17+ readonly class ExceptionFactory implements ExceptionFactoryInterface
1718{
1819 public function __construct (
19- private readonly \ OxidEsales \ Eshop \ Core \ Language $ language
20+ private Language $ language
2021 ) {
2122 }
2223
@@ -26,31 +27,26 @@ public function create(PasswordValidateException $exception): InputException
2627 return $ this ->createCollection ($ exception );
2728 }
2829
29- $ exception = oxNew (
30- InputException::class,
31- sprintf (
32- /** @phpstan-ignore-next-line */
33- $ this ->language ->translateString ($ exception ->getMessage ()),
34- ...$ exception ->getTranslationParameters ()
35- )
36- );
37-
38- return $ exception ;
30+ return oxNew (InputException::class, $ this ->formatExceptionMessage ($ exception ));
3931 }
4032
4133 private function createCollection (PasswordCollectionException $ collection ): InputException
4234 {
4335 $ lines = [];
44- foreach ($ collection ->getValidationExceptions () as $ ex ) {
45- $ lines [] = sprintf (
46- /** @phpstan-ignore-next-line */
47- $ this ->language ->translateString ($ ex ->getMessage ()),
48- ...$ ex ->getTranslationParameters ()
49- );
36+ foreach ($ collection ->getValidationExceptions () as $ exception ) {
37+ $ lines [] = $ this ->formatExceptionMessage ($ exception );
5038 }
51- /** @phpstan-ignore-next-line */
5239 $ message = '<ul><li> ' . implode ('</li><li> ' , $ lines ) . '</li></ul> ' ;
5340
5441 return oxNew (InputException::class, $ message );
5542 }
43+
44+ private function formatExceptionMessage (PasswordValidateException $ exception ): string
45+ {
46+ return sprintf (
47+ /** @phpstan-ignore-next-line */
48+ $ this ->language ->translateString ($ exception ->getMessage ()),
49+ ...$ exception ->getTranslationParameters ()
50+ );
51+ }
5652}
0 commit comments