Skip to content

Commit 7b0dca3

Browse files
committed
Use named parameters for the constraint constructors
1 parent 521085e commit 7b0dca3

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

src/Form/Type/ChangePasswordFormType.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public function __construct($class)
3636

3737
public function buildForm(FormBuilderInterface $builder, array $options): void
3838
{
39-
$constraintsOptions = [
40-
'message' => 'fos_user.current_password.invalid',
41-
];
39+
$groups = null;
4240

4341
if (!empty($options['validation_groups'])) {
44-
$constraintsOptions['groups'] = [reset($options['validation_groups'])];
42+
$groups = [reset($options['validation_groups'])];
4543
}
4644

4745
$builder->add('current_password', PasswordType::class, [
@@ -50,7 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5048
'mapped' => false,
5149
'constraints' => [
5250
new NotBlank(),
53-
new UserPassword($constraintsOptions),
51+
new UserPassword(message: 'fos_user.current_password.invalid', groups: $groups),
5452
],
5553
'attr' => [
5654
'autocomplete' => 'current-password',

src/Form/Type/ProfileFormType.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3838
{
3939
$this->buildUserForm($builder, $options);
4040

41-
$constraintsOptions = [
42-
'message' => 'fos_user.current_password.invalid',
43-
];
41+
$groups = null;
4442

4543
if (!empty($options['validation_groups'])) {
46-
$constraintsOptions['groups'] = [reset($options['validation_groups'])];
44+
$groups = [reset($options['validation_groups'])];
4745
}
4846

4947
$builder->add('current_password', PasswordType::class, [
@@ -52,7 +50,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5250
'mapped' => false,
5351
'constraints' => [
5452
new NotBlank(),
55-
new UserPassword($constraintsOptions),
53+
new UserPassword(message: 'fos_user.current_password.invalid', groups: $groups),
5654
],
5755
'attr' => [
5856
'autocomplete' => 'current-password',

0 commit comments

Comments
 (0)