<commit_before><?php

namespace InputValidation\Form;

use Symfony\Component\Translation\TranslatorInterface as Translator;
use InputValidation\Exception\FactoryException;
use InputValidation\Form;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class Factory
{
    /**
     * Namespace used by the factory method (see getForm())
     *
     * @var string
     */
    protected $_factoryNamespace = '';

    /**
     * Class name postfix used by the factory method (see getForm())
     *
     * @var string
     */
    protected $_factoryPostfix = 'Form';

    /**
     * @var Translator
     */
    protected $_translator = null;

    /**
     * @var Validator
     */
    protected $_validator = null;

    /**
     * @var OptionsInterface
     */
    private $options;

    /**
     * Form constructor.
     *
     * @param Translator $translator
     * @param Validator $validator
     * @param OptionsInterface $options
     */
    public function __construct(Translator $translator, Validator $validator, OptionsInterface $options)
    {
        $this->setTranslator($translator);
        $this->setValidator($validator);
        $this->setOptions($options);
    }

    /**
     * Returns a new form instance of the given name
     *
     * @param string $name Type of form
     * @param array $params Optional config parameters for init()
     * @throws FactoryException
     * @return Form
     */
    public function create(string $name, array $params = array()): Form
    {
        if (empty($name)) {
            throw new FactoryException ('create() requires a non-empty form name as first argument');
        }

        $className = $this->getFactoryNamespace() . '\\' . $name . $this->getFactoryPostfix();

        if (!class_exists($className)) {
            throw new FactoryException ('Form class "' . $className . '" does not exist');
        }

        $result = $this->createFormInstance($className, $params);

        return $result;
    }

    /**
     * Returns a new form instance of $className
     *
     * @param string $className
     * @param array $params
     * @return Form
     * @throws FactoryException
     */
    protected function createFormInstance(string $className, array $params)
    {
        $result = new $className ($this->getTranslator(), $this->getValidator(), $this->getOptions(), $params);

        return $result;
    }
<commit_msg>Removed factory type hint since PHP 7 does not support covariant return types<commit_after><?php

namespace InputValidation\Form;

use Symfony\Component\Translation\TranslatorInterface as Translator;
use InputValidation\Exception\FactoryException;
use InputValidation\Form;

/**
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */
class Factory
{
    /**
     * Namespace used by the factory method (see getForm())
     *
     * @var string
     */
    protected $_factoryNamespace = '';

    /**
     * Class name postfix used by the factory method (see getForm())
     *
     * @var string
     */
    protected $_factoryPostfix = 'Form';

    /**
     * @var Translator
     */
    protected $_translator = null;

    /**
     * @var Validator
     */
    protected $_validator = null;

    /**
     * @var OptionsInterface
     */
    private $options;

    /**
     * Form constructor.
     *
     * @param Translator $translator
     * @param Validator $validator
     * @param OptionsInterface $options
     */
    public function __construct(Translator $translator, Validator $validator, OptionsInterface $options)
    {
        $this->setTranslator($translator);
        $this->setValidator($validator);
        $this->setOptions($options);
    }

    /**
     * Returns a new form instance of the given name
     *
     * @param string $name Type of form
     * @param array $params Optional config parameters for init()
     * @throws FactoryException
     * @return Form
     */
    public function create(string $name, array $params = array())
    {
        if (empty($name)) {
            throw new FactoryException ('create() requires a non-empty form name as first argument');
        }

        $className = $this->getFactoryNamespace() . '\\' . $name . $this->getFactoryPostfix();

        if (!class_exists($className)) {
            throw new FactoryException ('Form class "' . $className . '" does not exist');
        }

        $result = $this->createFormInstance($className, $params);

        return $result;
    }

    /**
     * Returns a new form instance of $className
     *
     * @param string $className
     * @param array $params
     * @return Form
     * @throws FactoryException
     */
    protected function createFormInstance(string $className, array $params)
    {
        $result = new $className ($this->getTranslator(), $this->getValidator(), $this->getOptions(), $params);

        return $result;
    }

{'fraction_non_alphanumeric': 0.12184526272238312, 'fraction_numerical': 0.0002068680182043856, 'mean_word_length': 2.448644793152639, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '3786670', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1291, 'n_words': 375}