<commit_before><?php

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

namespace Pecserke\Bundle\TwigDoctrineLoaderBundle\Twig\Loader;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ODM\MongoDB\DocumentRepository as MongoDBDocumentRepository;
use Doctrine\ORM\EntityRepository;
use Pecserke\Bundle\TwigDoctrineLoaderBundle\Model\Template;

/**
 * Loads template from database using Doctrine 2.
 *
 * @author <NAME> <<EMAIL>>
 */
class Doctrine implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface
{
    /**
     * @var ObjectRepository
     */
    protected $templateRepository;

    /**
     * @var string
     */
    protected $cacheKeyPrefix;

    /**
     * @param ObjectRepository $templateRepository
     * @param string $cacheKeyPrefix
     */
    public function __construct(ObjectRepository $templateRepository, $cacheKeyPrefix)
    {
        $this->templateRepository = $templateRepository;
        $this->cacheKeyPrefix = $cacheKeyPrefix;
    }

    /**
     * {@inheritdoc}
     */
    public function exists($name)
    {
        $repo = $this->templateRepository;

        if (class_exists('Doctrine\ORM\EntityRepository') && $repo instanceof EntityRepository) {
            $qb = $repo->createQueryBuilder('t');
            $qb
                ->select('count(t)')
                ->where($qb->expr()->eq('t.name', ':name'))
                ->setParameter('name', $name)
            ;

            return $qb->getQuery()->getSingleScalarResult() !== 0;
        }

        if (class_exists('Doctrine\ODM\MongoDB\DocumentRepository') && $repo instanceof MongoDBDocumentRepository) {
            $qb = $repo->createQueryBuilder()->field('name')->equals($name);

            return $qb->getQuery()->execute()->count() !== 0;
        }<commit_msg>Fixed Twig Loader wrong "exists" check result <commit_after><?php

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

namespace Pecserke\Bundle\TwigDoctrineLoaderBundle\Twig\Loader;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ODM\MongoDB\DocumentRepository as MongoDBDocumentRepository;
use Doctrine\ORM\EntityRepository;
use Pecserke\Bundle\TwigDoctrineLoaderBundle\Model\Template;

/**
 * Loads template from database using Doctrine 2.
 *
 * @author <NAME> <<EMAIL>>
 */
class Doctrine implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface
{
    /**
     * @var ObjectRepository
     */
    protected $templateRepository;

    /**
     * @var string
     */
    protected $cacheKeyPrefix;

    /**
     * @param ObjectRepository $templateRepository
     * @param string $cacheKeyPrefix
     */
    public function __construct(ObjectRepository $templateRepository, $cacheKeyPrefix)
    {
        $this->templateRepository = $templateRepository;
        $this->cacheKeyPrefix = $cacheKeyPrefix;
    }

    /**
     * {@inheritdoc}
     */
    public function exists($name)
    {
        $repo = $this->templateRepository;

        if (class_exists('Doctrine\ORM\EntityRepository') && $repo instanceof EntityRepository) {
            $qb = $repo->createQueryBuilder('t');
            $qb
                ->select('count(t)')
                ->where($qb->expr()->eq('t.name', ':name'))
                ->setParameter('name', $name)
            ;

            return (int) $qb->getQuery()->getSingleScalarResult() !== 0;
        }

        if (class_exists('Doctrine\ODM\MongoDB\DocumentRepository') && $repo instanceof MongoDBDocumentRepository) {
            $qb = $repo->createQueryBuilder()->field('name')->equals($name);

            return $qb->getQuery()->execute()->count() !== 0;
        }
{'fraction_non_alphanumeric': 0.13423870462261686, 'fraction_numerical': 0.0015669887699138157, 'mean_word_length': 2.9041794087665647, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 49, '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': '7285529', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1060, 'n_words': 218}