<commit_before><?php

/*
 * This file is part of the Integrated package.
 *
 * (c) e-Active B.V. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Integrated\Bundle\UserBundle\Form\Type;

use Integrated\Bundle\UserBundle\Form\DataMapper\UserMapper;
use Integrated\Bundle\UserBundle\Form\EventListener\UserProfileExtensionListener;
use Integrated\Bundle\UserBundle\Form\EventListener\UserProfileOptionalListener;
use Integrated\Bundle\UserBundle\Form\EventListener\UserProfilePasswordListener;

use Integrated\Bundle\UserBundle\Model\UserManagerInterface;
use Integrated\Bundle\UserBundle\Validator\Constraints\UniqueUser;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;

use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\Util\SecureRandomInterface;

use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;

use ReflectionClass;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ProfileFormType extends AbstractType
{
    /**
     * @var UserManagerInterface
     */
    private $manager;

    /**
     * @var SecureRandomInterface
     */
    private $generator;

    /**
     * @var EncoderFactoryInterface
     */
    private $encoderFactory;

    /**
     * Constructor.
     *
     * @param UserManagerInterface $manager
     * @param SecureRandomInterface $generator
     * @param EncoderFactoryInterface $encoder
     */
    public function __construct(UserManagerInterface $manager, SecureRandomInterface $generator, EncoderFactoryInterface $encoder)
    {
        $this->manager = $manager;

        $this->generator = $generator;
        $this->encoderFactory = $encoder;
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['optional']) {
            $builder->add('enabled', 'checkbox', [
                'mapped' => false,
                'required' => false,
                'label' => 'Enable login'
            ]);

            // this has to be a event listener as data will not be mapped to this
            // field, even if mapped is set to true, when the field value is false.

            $builder->addEventSubscriber(new UserProfileOptionalListener());
        }

        $builder->add('username', 'text', [
            'constraints' => [
                new NotBlank(),
                new Length(['min' => 3])
            ],
            'attr' => ['autocomplete' => 'off']
        ]);

        $builder->add('password', 'password', [
            'mapped' => false,
            'constraints' => [
                new NotBlank(),
                new Length(['min' => 6])
            ],
            'attr' => ['autocomplete' => 'off']
        ]);

        if (!$options['optional']) {
            $builder->add('enabled', 'checkbox', [
                'required' => false,
                'label' => 'Enable login'
            ]);
        }

        $builder->add('groups', 'user_group_choice');

        $builder->addEventSubscriber(new UserProfilePasswordListener($this->generator, $this->encoderFactory));
        $builder->addEventSubscriber(new UserProfileExtensionListener('integrated.extension.user'));

        if ($options['optional']) {
            $builder->setDataMapper(new UserMapper());
        }
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $emptyData = function (Options $options, $previous) {
            if (!$options['optional']) {
                return $this->getManager()->create(); // if not optional then it should always return a user
            }
<commit_msg>Groups should be multiple and expanded<commit_after><?php

/*
 * This file is part of the Integrated package.
 *
 * (c) e-Active B.V. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Integrated\Bundle\UserBundle\Form\Type;

use Integrated\Bundle\UserBundle\Form\DataMapper\UserMapper;
use Integrated\Bundle\UserBundle\Form\EventListener\UserProfileExtensionListener;
use Integrated\Bundle\UserBundle\Form\EventListener\UserProfileOptionalListener;
use Integrated\Bundle\UserBundle\Form\EventListener\UserProfilePasswordListener;

use Integrated\Bundle\UserBundle\Model\UserManagerInterface;
use Integrated\Bundle\UserBundle\Validator\Constraints\UniqueUser;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;

use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\Util\SecureRandomInterface;

use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;

use ReflectionClass;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ProfileFormType extends AbstractType
{
    /**
     * @var UserManagerInterface
     */
    private $manager;

    /**
     * @var SecureRandomInterface
     */
    private $generator;

    /**
     * @var EncoderFactoryInterface
     */
    private $encoderFactory;

    /**
     * Constructor.
     *
     * @param UserManagerInterface $manager
     * @param SecureRandomInterface $generator
     * @param EncoderFactoryInterface $encoder
     */
    public function __construct(UserManagerInterface $manager, SecureRandomInterface $generator, EncoderFactoryInterface $encoder)
    {
        $this->manager = $manager;

        $this->generator = $generator;
        $this->encoderFactory = $encoder;
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['optional']) {
            $builder->add('enabled', 'checkbox', [
                'mapped' => false,
                'required' => false,
                'label' => 'Enable login'
            ]);

            // this has to be a event listener as data will not be mapped to this
            // field, even if mapped is set to true, when the field value is false.

            $builder->addEventSubscriber(new UserProfileOptionalListener());
        }

        $builder->add('username', 'text', [
            'constraints' => [
                new NotBlank(),
                new Length(['min' => 3])
            ],
            'attr' => ['autocomplete' => 'off']
        ]);

        $builder->add('password', 'password', [
            'mapped' => false,
            'constraints' => [
                new NotBlank(),
                new Length(['min' => 6])
            ],
            'attr' => ['autocomplete' => 'off']
        ]);

        if (!$options['optional']) {
            $builder->add('enabled', 'checkbox', [
                'required' => false,
                'label' => 'Enable login'
            ]);
        }

        $builder->add('groups', 'user_group_choice', [
            'multiple' => true,
            'expanded' => true
        ]);

        $builder->addEventSubscriber(new UserProfilePasswordListener($this->generator, $this->encoderFactory));
        $builder->addEventSubscriber(new UserProfileExtensionListener('integrated.extension.user'));

        if ($options['optional']) {
            $builder->setDataMapper(new UserMapper());
        }
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $emptyData = function (Options $options, $previous) {
            if (!$options['optional']) {
                return $this->getManager()->create(); // if not optional then it should always return a user
            }

{'fraction_non_alphanumeric': 0.12470675392023707, 'fraction_numerical': 0.0004938881343375726, 'mean_word_length': 2.587245349867139, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3282673', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2062, 'n_words': 467}