Refactor helper drift in lib: centralize theme/translation and remove app() hotspots

This commit is contained in:
2026-03-19 08:23:14 +01:00
parent 5da506a20f
commit 5739cc1200
24 changed files with 197 additions and 88 deletions

View File

@@ -2,8 +2,12 @@
namespace MintyPHP\Service\User;
use MintyPHP\Service\I18n\TranslatesServiceText;
class UserPasswordPolicyService
{
use TranslatesServiceText;
private const PASSWORD_MIN_LENGTH = 12;
public function validate(string $password, string $password2, bool $required, ?string $email): array
@@ -61,15 +65,4 @@ class UserPasswordPolicyService
return self::PASSWORD_MIN_LENGTH;
}
// Wrapper so this service can be used in tests before the t() helper is loaded.
private function translate(string $text, mixed ...$args): string
{
if (function_exists('t')) {
return t($text, ...$args);
}
if ($args === []) {
return $text;
}
return vsprintf($text, array_map(static fn ($arg) => (string) $arg, $args));
}
}