Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ChangePasswordFormType
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 buildForm
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
2
 configureOptions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Form;
4
5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\Extension\Core\Type\PasswordType;
7use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
8use Symfony\Component\Form\FormBuilderInterface;
9use Symfony\Component\OptionsResolver\OptionsResolver;
10use Symfony\Component\Validator\Constraints\Length;
11use Symfony\Component\Validator\Constraints\NotBlank;
12
13class ChangePasswordFormType extends AbstractType
14{
15    public function buildForm(FormBuilderInterface $builder, array $options): void
16    {
17        $builder
18            ->add(child: 'plainPassword', type: RepeatedType::class, options: [
19                'type' => PasswordType::class,
20                'options' => [
21                    'attr' => [
22                        'autocomplete' => 'new-password',
23                    ],
24                ],
25                'first_options' => [
26                    'constraints' => [
27                        new NotBlank(options: [
28                            'message' => 'Please enter a password',
29                        ]),
30                        new Length(exactly: [
31                            'min' => 6,
32                            'minMessage' => 'Your password should be at least {{ limit }} characters',
33                            // max length allowed by Symfony for security reasons
34                            'max' => 4096,
35                        ]),
36                    ],
37                    'label' => 'New password',
38                ],
39                'second_options' => [
40                    'label' => 'Repeat Password',
41                ],
42                'invalid_message' => 'The password fields must match.',
43                // Instead of being set onto the object directly,
44                // this is read and encoded in the controller
45                'mapped' => false,
46            ])
47        ;
48    }
49
50    public function configureOptions(OptionsResolver $resolver): void
51    {
52        $resolver->setDefaults(defaults: []);
53    }
54}