<commit_before><?php

namespace Contrask\Test\Component\Project;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Configuration;

/**
 * @author <NAME> <<EMAIL>>
 */
class EntityManagerBuilder
{
    /**
     * Creates entity manager
     *
     * @param array $entities
     * @param array $listeners
     * @param array $targetEntities
     * @return EntityManager
     */
    public function createEntityManager($entities = array(), $listeners = array(), $targetEntities = array())
    {
        $conn = array(
            'driver' => 'pdo_sqlite',
            'memory' => true,
        );

        $config = $this->createConfig();

        $evm = $this->createEventManager($listeners, $targetEntities);

        $em = EntityManager::create($conn, $config, $evm);

        $schemaTool = new SchemaTool($em);
        $schemaTool->dropSchema(array());
        $schemaTool->createSchema(
            array_map(
                function($class) use ($em) {
                    return $em->getClassMetadata($class);
                },
                $entities
            )
        );

        return $em;
    }

    /**
     * Creates configuration
     *
     * @return \Doctrine\ORM\Configuration
     */
    private function createConfig()
    {
        $config = new Configuration();
        $config->setProxyDir(sys_get_temp_dir());
        $config->setProxyNamespace('Proxy');
        $config->setAutoGenerateProxyClasses(true);
        $config->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
        $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
        $config->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
        $config->setQuoteStrategy(new DefaultQuoteStrategy());
        $config->setNamingStrategy(new DefaultNamingStrategy());
        $config->setRepositoryFactory(new DefaultRepositoryFactory());

        return $config;
    }

    /**
     * Creates entity manager
     *
     * @param array $listeners<commit_msg>Changes in EntityManagerBuilder<commit_after><?php

namespace Cubalider\Test\Component\Sms;

use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Configuration;

class EntityManagerBuilder
{
    /**
     * Creates entity manager
     *
     * @param array $mappings
     * @param array $entities
     * @param array $listeners
     * @param array $targetEntities
     * @return EntityManager
     */
    public function createEntityManager(
        $mappings = array(),
        $entities = array(),
        $listeners = array(),
        $targetEntities = array()
    )
    {
        $conn = array(
            'driver' => 'pdo_sqlite',
            'memory' => true,
        );

        $config = $this->createConfig($mappings);

        $evm = $this->createEventManager($listeners, $targetEntities);

        $em = EntityManager::create($conn, $config, $evm);

        $schemaTool = new SchemaTool($em);
        $schemaTool->dropSchema(array());
        $schemaTool->createSchema(
            array_map(
                function($class) use ($em) {
                    return $em->getClassMetadata($class);
                },
                $entities
            )
        );

        return $em;
    }

    /**
     * Creates configuration
     *
     * @param array $mappings
     * @return \Doctrine\ORM\Configuration
     */
    private function createConfig($mappings)
    {
        $config = new Configuration();
        $config->setProxyDir(sys_get_temp_dir());
        $config->setProxyNamespace('Proxy');
        $config->setAutoGenerateProxyClasses(true);
        $config->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
        $config->setMetadataDriverImpl(new XmlDriver($mappings));
        $config->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
        $config->setQuoteStrategy(new DefaultQuoteStrategy());
        $config->setNamingStrategy(new DefaultNamingStrategy());
        $config->setRepositoryFactory(new DefaultRepositoryFactory());

        return $config;
    }

    /**
     * Creates entity manager
     *
     * @param array $listeners
{'fraction_non_alphanumeric': 0.12322567372968525, 'fraction_numerical': 0.0, 'mean_word_length': 2.763157894736842, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 38, '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': '6986517', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1304, 'n_words': 230}