<commit_before><?php

/*
 * This file is part of the NelmioApiDocBundle.
 *
 * (c) Nelmio <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nelmio\ApiDocBundle\Parser;

use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;

class FormTypeParser
{
    /**
     * @var \Symfony\Component\Form\FormFactoryInterface
     */
    protected $formFactory;

    /**
     * @var array
     */
    protected $mapTypes = array(
        'text'      => 'string',
        'date'      => 'date',
        'datetime'  => 'datetime',
        'checkbox'  => 'boolean',
        'time'      => 'time',
        'number'    => 'float',
        'integer'   => 'int',
        'textarea'  => 'string',
    );

    public function __construct(FormFactoryInterface $formFactory)
    {
        $this->formFactory = $formFactory;
    }

    /**
     * Returns an array of data where each data is an array with the following keys:
     *  - dataType
     *  - required
     *  - description
     *
     * @param  string|\Symfony\Component\Form\FormTypeInterface $type
     * @return array
     */
    public function parse($type)
    {
        if (is_string($type) && class_exists($type)) {
            $type = new $type();
        }
        $form = $this->formFactory->create($type);

        $parameters = array();
        foreach ($form as $name => $child) {
            $config = $child->getConfig();

            $bestType = '';
            foreach ($config->getTypes() as $type) {
                if (isset($this->mapTypes[$type->getName()])) {
                    $bestType = $this->mapTypes[$type->getName()];
                }
            }

            $parameters[$name] = array(
                'dataType'      => $bestType,
                'required'      => $config->getRequired(),
                'description'   => $config->getAttribute('description'),
            );
        }

        return $parameters;
    }
}<commit_msg>Fix FormTypeParser to reflect last Symfony2 changes<commit_after><?php

/*
 * This file is part of the NelmioApiDocBundle.
 *
 * (c) Nelmio <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nelmio\ApiDocBundle\Parser;

use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;

class FormTypeParser
{
    /**
     * @var \Symfony\Component\Form\FormFactoryInterface
     */
    protected $formFactory;

    /**
     * @var array
     */
    protected $mapTypes = array(
        'text'      => 'string',
        'date'      => 'date',
        'datetime'  => 'datetime',
        'checkbox'  => 'boolean',
        'time'      => 'time',
        'number'    => 'float',
        'integer'   => 'int',
        'textarea'  => 'string',
    );

    public function __construct(FormFactoryInterface $formFactory)
    {
        $this->formFactory = $formFactory;
    }

    /**
     * Returns an array of data where each data is an array with the following keys:
     *  - dataType
     *  - required
     *  - description
     *
     * @param  string|\Symfony\Component\Form\FormTypeInterface $type
     * @return array
     */
    public function parse($type)
    {
        if (is_string($type) && class_exists($type)) {
            $type = new $type();
        }
        $form = $this->formFactory->create($type);

        $parameters = array();
        foreach ($form as $name => $child) {
            $config = $child->getConfig();

            $bestType = '';
            for ($type = $config->getType(); null !== $type; $type = $type->getParent()) {
                if (isset($this->mapTypes[$type->getName()])) {
                    $bestType = $this->mapTypes[$type->getName()];
                }
            }

            $parameters[$name] = array(
                'dataType'      => $bestType,
                'required'      => $config->getRequired(),
                'description'   => $config->getAttribute('description'),
            );
        }

        return $parameters;
    }
}
{'fraction_non_alphanumeric': 0.14272030651340997, 'fraction_numerical': 0.00023946360153256704, 'mean_word_length': 1.9047287899860919, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 54, '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': '4194408', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1172, 'n_words': 271}