<commit_before><?php
namespace Vanio\WebBundle\Form;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PreserveMissingDataExtension extends AbstractTypeExtension
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['preserve_missing_data']) {
            $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit'], 100);
        }
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefault('preserve_missing_data', false)
            ->setAllowedTypes('preserve_missing_data', 'bool');
    }

    public function getExtendedType(): string
    {
        return FormType::class;
    }

    /**
     * @param FormEvent $event
     */
    public function onPreSubmit(FormEvent $event)
    {
        $event->setData($this->resolveSubmittedData($event->getForm(), $event->getData()));
    }

    /**
     * @param FormInterface $form
     * @return mixed[]|string
     */
    private function resolveSubmittedData(FormInterface $form, $data = null)
    {
        if ($form->count()) {
            if (!is_array($data)) {
                $data = [];
            }

            foreach ($form->all() as $name => $child) {
                if (!isset($data[$name])) {
                    $data[$name] = $this->resolveSubmittedData($child);
                }
            }

            return $data;
        } elseif ($data === null) {
            $data = $form->getViewData();
        }

        return is_array($data) ? $data : (string) $data;
    }
}
<commit_msg>* Skipping checkboxes in PreserveMissingDataExtension * Stopped casting data to string in PreserveMissingDataExtension when form is compound<commit_after><?php
namespace Vanio\WebBundle\Form;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PreserveMissingDataExtension extends AbstractTypeExtension
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['preserve_missing_data']) {
            $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit'], 100);
        }
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefault('preserve_missing_data', false)
            ->setAllowedTypes('preserve_missing_data', 'bool');
    }

    public function getExtendedType(): string
    {
        return FormType::class;
    }

    /**
     * @param FormEvent $event
     */
    public function onPreSubmit(FormEvent $event)
    {
        $event->setData($this->resolveSubmittedData($event->getForm(), $event->getData()));
    }

    /**
     * @param FormInterface $form
     * @return mixed[]|string
     */
    private function resolveSubmittedData(FormInterface $form, $data = null)
    {
        if ($form->count()) {
            if (!is_array($data)) {
                $data = [];
            }

            foreach ($form->all() as $name => $child) {
                if (!isset($data[$name]) && !$child->getConfig()->getType()->getInnerType() instanceof CheckboxType) {
                    $data[$name] = $this->resolveSubmittedData($child);
                }
            }

            return $data;
        } elseif ($data === null) {
            $data = $form->getViewData();
        }

        if ($data === null && $form->getConfig()->getCompound()) {
            return null;
        }

        return is_array($data) ? $data : (string) $data;
    }
}

{'fraction_non_alphanumeric': 0.1284722222222222, 'fraction_numerical': 0.001388888888888889, 'mean_word_length': 2.7737991266375546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '6629782', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1171, 'n_words': 222}