From 5165e959531397e69d0ed1561744bf6f1ebb7695 Mon Sep 17 00:00:00 2001 From: octoseth <71984208+octoseth@users.noreply.github.com> Date: Mon, 4 Aug 2025 21:07:24 +0200 Subject: [PATCH] Refactor constraints to use named arguments --- src/Maker/MakeRegistrationForm.php | 18 +++++++----------- .../ChangePasswordFormType.tpl.php | 14 ++++++-------- .../ResetPasswordRequestFormType.tpl.php | 4 +--- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index 48a8ae34a..f4a1f54e5 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -559,9 +559,7 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator 'options_code' => << false, 'constraints' => [ - new IsTrue([ - 'message' => 'You should agree to our terms.', - ]), + new IsTrue(message: 'You should agree to our terms.'), ], EOF ], @@ -573,15 +571,13 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator 'mapped' => false, 'attr' => ['autocomplete' => 'new-password'], 'constraints' => [ - new NotBlank([ - 'message' => 'Please enter a password', - ]), - new Length([ - 'min' => 6, - 'minMessage' => 'Your password should be at least {{ limit }} characters', + new NotBlank(message: 'Please enter a password'), + new Length( + min: 6, + minMessage: 'Your password should be at least {{ limit }} characters', // max length allowed by Symfony for security reasons - 'max' => 4096, - ]), + max: 4096 + ), ], EOF ], diff --git a/templates/resetPassword/ChangePasswordFormType.tpl.php b/templates/resetPassword/ChangePasswordFormType.tpl.php index 95eb7410f..2e83d3423 100644 --- a/templates/resetPassword/ChangePasswordFormType.tpl.php +++ b/templates/resetPassword/ChangePasswordFormType.tpl.php @@ -18,15 +18,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], 'first_options' => [ 'constraints' => [ - new NotBlank([ - 'message' => 'Please enter a password', - ]), - new Length([ - 'min' => 12, - 'minMessage' => 'Your password should be at least {{ limit }} characters', + new NotBlank(message: 'Please enter a password'), + new Length( + min: 12, + minMessage: 'Your password should be at least {{ limit }} characters', // max length allowed by Symfony for security reasons - 'max' => 4096, - ]), + max: 4096 + ), new PasswordStrength(), new NotCompromisedPassword(), ], diff --git a/templates/resetPassword/ResetPasswordRequestFormType.tpl.php b/templates/resetPassword/ResetPasswordRequestFormType.tpl.php index fdb8b93a1..1212059f6 100644 --- a/templates/resetPassword/ResetPasswordRequestFormType.tpl.php +++ b/templates/resetPassword/ResetPasswordRequestFormType.tpl.php @@ -12,9 +12,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('', EmailType::class, [ 'attr' => ['autocomplete' => 'email'], 'constraints' => [ - new NotBlank([ - 'message' => 'Please enter your email', - ]), + new NotBlank(message: 'Please enter your email'), ], ]) ;