<commit_before><?php

namespace ParaunitTestCase\Client;

use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Client;

/**
 * Class ParaunitTestClient
 * @package Facile\Cbr\CoreBundle\Tests
 */
class ParaunitTestClient extends Client
{
    /**
     * This method checks that the EM is still valid and avoids rebooting the kernel.
     * The EM is cleared every time to avoid inconsistencies.
     * If something broke the EntityManager, the connection is closed, to avoid further usage.
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     * @throws \Doctrine\ORM\ORMException
     */
    protected function doRequest($request)
    {
        /** @var AbstractManagerRegistry $doctrine */
        $doctrine = $this->getContainer()->get('doctrine');
        /** @var EntityManagerInterface $manager */
        foreach ($doctrine->getManagers() as $manager) {
            $this->handleManager($manager);
        }

        return $this->kernel->handle($request);
    }

    /**
     * @param EntityManagerInterface $manager
     */
    private function handleManager(EntityManagerInterface $manager)
    {
        $manager->clear();

        if ( ! $manager->isOpen()) {
            $manager->getConnection()->close();
        }
    }
}
<commit_msg>Had parameter to reboot the kernel anyway when doing a request<commit_after><?php

namespace ParaunitTestCase\Client;

use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Client;

/**
 * Class ParaunitTestClient
 * @package Facile\Cbr\CoreBundle\Tests
 */
class ParaunitTestClient extends Client
{
    /**
     * This method checks that the EM is still valid and avoids rebooting the kernel.
     * The EM is cleared every time to avoid inconsistencies.
     * If something broke the EntityManager, the connection is closed, to avoid further usage.
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @param bool $rebootKernel If true, reboots the kernel anyway: needed when the container has stale services
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function doRequest($request, $rebootKernel = false)
    {
        if ($rebootKernel) {
            return parent::doRequest($request);
        }

        /** @var AbstractManagerRegistry $doctrine */
        $doctrine = $this->getContainer()->get('doctrine');
        /** @var EntityManagerInterface $manager */
        foreach ($doctrine->getManagers() as $manager) {
            $this->handleManager($manager);
        }

        return $this->kernel->handle($request);
    }

    /**
     * @param EntityManagerInterface $manager
     */
    private function handleManager(EntityManagerInterface $manager)
    {
        $manager->clear();

        if ( ! $manager->isOpen()) {
            $manager->getConnection()->close();
        }
    }
}

{'fraction_non_alphanumeric': 0.11009174311926606, 'fraction_numerical': 0.0, 'mean_word_length': 2.964935064935065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3012516', 'n_tokens_mistral': 800, 'n_tokens_neox': 782, 'n_words': 208}