<commit_before><?php

namespace Lexik\Bundle\FormFilterBundle\Filter\Extension\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Translation\TranslatorInterface;

use Doctrine\ORM\QueryBuilder;

/**
 * Filter to use with boolean values.
 *
 * @author <NAME> <<EMAIL>>
 */
class BooleanFilterType extends AbstractType implements FilterTypeInterface
{
    const VALUE_YES = 'y';
    const VALUE_NO  = 'n';

    /**
     * @var TranslatorInterface
     */
    protected $translator;

    /**
     * {@inheritdoc}
     */
    public function getParent(array $options)
    {
        return 'filter_choice';
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'filter_boolean';
    }

    /**
     * {@inheritdoc}
     */
    public function getDefaultOptions(array $options)
    {
        return array(
            'choices' => array(
                self::VALUE_YES  => $this->trans('boolean.yes'),
                self::VALUE_NO   => $this->trans('boolean.no'),
            ),
            'empty_value' => $this->trans('boolean.yes_or_no'),
        );
    }

    /**
     * Set Translator
     *
     * @param TranslatorInterface $translator
     */
    public function setTranslator(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }

    /**
     * Translate a key for a domain
     *
     * @param string $key
     * @param array  $parameters
     * @param string $domain
     *
     * @return string
     */
    private function trans($key, array $parameters = array(), $domain = 'LexikFormFilterBundle')
    {
        return $this->translator->trans($key, $parameters, $domain);
    }

    /**
     * {@inheritdoc}
     */
    public function getTransformerId()
    {
        return 'lexik_form_filter.transformer.default';
    }

    /**
     * {@inheritdoc}
     */
    public function applyFilter(QueryBuilder $queryBuilder, $field, $values)
    {
        if (!empty($values['value'])) {
            $paramName = sprintf('%s_param', $field);

            $queryBuilder->andWhere(sprintf('%s.%s = :%s', $queryBuilder->getRootAlias(), $field, $paramName))
                ->setParameter($paramName, (int) (self::VALUE_YES == $values['value']), \PDO::PARAM_BOOL);
        }
    }
}<commit_msg>check translator is an instance of TranslatorInterface before use it<commit_after><?php

namespace Lexik\Bundle\FormFilterBundle\Filter\Extension\Type;

use Symfony\Bridge\Twig\Extension\TranslationExtension;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Translation\TranslatorInterface;

use Doctrine\ORM\QueryBuilder;

/**
 * Filter to use with boolean values.
 *
 * @author <NAME> <<EMAIL>>
 */
class BooleanFilterType extends AbstractType implements FilterTypeInterface
{
    const VALUE_YES = 'y';
    const VALUE_NO  = 'n';

    /**
     * @var Symfony\Component\Translation\TranslatorInterface
     */
    protected $translator;

    /**
     * {@inheritdoc}
     */
    public function getParent(array $options)
    {
        return 'filter_choice';
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'filter_boolean';
    }

    /**
     * {@inheritdoc}
     */
    public function getDefaultOptions(array $options)
    {
        return array(
            'choices' => array(
                self::VALUE_YES  => $this->trans('boolean.yes'),
                self::VALUE_NO   => $this->trans('boolean.no'),
            ),
            'empty_value' => $this->trans('boolean.yes_or_no'),
        );
    }

    /**
     * Set Translator
     *
     * @param TranslatorInterface $translator
     */
    public function setTranslator(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }

    /**
     * Translate a key for a domain
     *
     * @param string $key
     * @param array  $parameters
     * @param string $domain
     *
     * @return string
     */
    private function trans($key, array $parameters = array(), $domain = 'LexikFormFilterBundle')
    {
        return ($this->translator instanceof TranslatorInterface) ? $this->translator->trans($key, $parameters, $domain) : $key;
    }

    /**
     * {@inheritdoc}
     */
    public function getTransformerId()
    {
        return 'lexik_form_filter.transformer.default';
    }

    /**
     * {@inheritdoc}
     */
    public function applyFilter(QueryBuilder $queryBuilder, $field, $values)
    {
        if (!empty($values['value'])) {
            $paramName = sprintf('%s_param', $field);

            $queryBuilder->andWhere(sprintf('%s.%s = :%s', $queryBuilder->getRootAlias(), $field, $paramName))
                ->setParameter($paramName, (int) (self::VALUE_YES == $values['value']), \PDO::PARAM_BOOL);
        }
    }
}
{'fraction_non_alphanumeric': 0.14035087719298245, 'fraction_numerical': 0.0, 'mean_word_length': 2.374911909795631, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 36, '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': '3214479', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1405, 'n_words': 275}