Skip to content

Commit 8bdd829

Browse files
committed
OXDEV-8786 Remove unnecessary phpstan ignore line and refactor ExceptionFactory
1 parent 4064bfe commit 8bdd829

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

src/PasswordPolicy/Intrastructure/ExceptionFactory.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
namespace OxidEsales\SecurityModule\PasswordPolicy\Intrastructure;
1111

1212
use OxidEsales\Eshop\Core\Exception\InputException;
13+
use OxidEsales\Eshop\Core\Language;
1314
use OxidEsales\SecurityModule\PasswordPolicy\Validation\Exception\PasswordCollectionException;
1415
use 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

Comments
 (0)