Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
10 / 10 |
| FormFields | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
10 / 10 |
| repeated_password | |
100.00% |
1 / 1 |
1 | |
100.00% |
10 / 10 |
|||
| password | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Util\Form; |
| 4 | |
| 5 | use function App\Core\I18n\_m; |
| 6 | use App\Util\Common; |
| 7 | use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
| 8 | use Symfony\Component\Form\Extension\Core\Type\RepeatedType; |
| 9 | use Symfony\Component\Validator\Constraints\Length; |
| 10 | use Symfony\Component\Validator\Constraints\NotBlank; |
| 11 | |
| 12 | abstract class FormFields |
| 13 | { |
| 14 | public static function repeated_password(array $options = []): array |
| 15 | { |
| 16 | return ['password', RepeatedType::class, |
| 17 | ['type' => PasswordType::class, |
| 18 | 'first_options' => [ |
| 19 | 'label' => _m('Password'), |
| 20 | 'label_attr' => ['class' => 'section-form-label'], |
| 21 | 'attr' => ['placeholder' => '********'], |
| 22 | 'required' => $options['required'] ?? true, |
| 23 | |
| 24 | 'constraints' => [ |
| 25 | new NotBlank(['message' => _m('Please enter a password')]), |
| 26 | new Length(['min' => Common::config('password', 'min_length'), 'minMessage' => _m(['Your password should be at least # characters'], ['count' => Common::config('password', 'min_length')]), |
| 27 | 'max' => Common::config('password', 'max_length'), 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => Common::config('password', 'max_length')]), ]), |
| 28 | ], |
| 29 | 'help' => _m('Write a password with at least {min_length} characters, and a maximum of {max_length}.', ['min_length' => Common::config('password', 'min_length'), 'max_length' => Common::config('password', 'max_length')]), |
| 30 | ], |
| 31 | 'second_options' => [ |
| 32 | 'label' => _m('Repeat Password'), |
| 33 | 'label_attr' => ['class' => 'section-form-label'], |
| 34 | 'attr' => ['placeholder' => '********'], |
| 35 | 'help' => _m('Confirm your password.'), |
| 36 | ], |
| 37 | 'mapped' => false, |
| 38 | 'invalid_message' => _m('The password fields must match'), |
| 39 | ], |
| 40 | ]; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @codeCoverageIgnore |
| 45 | */ |
| 46 | public static function password(array $options = []): array |
| 47 | { |
| 48 | ['password', PasswordType::class, [ |
| 49 | 'label' => _m('Password'), |
| 50 | 'label_attr' => ['class' => 'section-form-label'], |
| 51 | 'attr' => ['placeholder' => '********'], |
| 52 | 'required' => $options['required'] ?? true, |
| 53 | 'mapped' => false, |
| 54 | 'constraints' => [ |
| 55 | new NotBlank(['message' => _m('Please enter a password')]), |
| 56 | new Length(['min' => Common::config('password', 'min_length'), 'minMessage' => _m(['Your password should be at least # characters'], ['count' => Common::config('password', 'min_length')]), |
| 57 | 'max' => Common::config('password', 'max_length'), 'maxMessage' => _m(['Your password should be at most # characters'], ['count' => Common::config('password', 'max_length')]), ]), |
| 58 | ], ], |
| 59 | ]; |
| 60 | } |
| 61 | } |