<commit_before><?php

namespace FOQ\ElasticaBundle\Manager;

use Doctrine\Common\Annotations\Reader;
use FOQ\ElasticaBundle\Finder\FinderInterface;
use RuntimeException;
/**
 * @author <NAME> <<EMAIL>>
 *
 * Allows retrieval of basic or custom repository for mapped Doctrine
 * entities/documents.
 */
class RepositoryManager implements RepositoryManagerInterface
{
    protected $entities = array();
    protected $repositories = array();
    protected $reader;

    public function __construct(Reader $reader)
    {
        $this->reader = $reader;
    }

    public function addEntity($entityName, FinderInterface $finder, $repositoryName = null)
    {
        $this->entities[$entityName]= array();
        $this->entities[$entityName]['finder'] = $finder;
        $this->entities[$entityName]['repositoryName'] = $repositoryName;
    }

    /**
     * Return repository for entity
     *
     * Returns custom repository if one specified otherwise
     * returns a basic respository.
     */
    public function getRepository($entityName)
    {
        if (isset($this->repositories[$entityName])) {
            return $this->repositories[$entityName];
        }

        if (!isset($this->entities[$entityName])) {
            throw new RuntimeException(sprintf('No search finder configured for %s', $entityName));
        }

        $repositoryName = $this->getRepositoryName($entityName);
        if (!class_exists($repositoryName)) {
            throw new RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $entityName));
        }
        $repository = new $repositoryName($this->entities[$entityName]['finder']);
        $this->repositories[$entityName] = $repository;

        return $repository;
    }

    protected function getRepositoryName($realEntityName)
    {
        if (isset($this->entities[$realEntityName]['repositoryName'])) {
            return $this->entities[$realEntityName]['repositoryName'];
        }

        $refClass   = new \ReflectionClass($realEntityName);
        $annotation = $this->reader->getClassAnnotation($refClass, 'FOQ\\ElasticaBundle\\Configuration\\Search');
        if ($annotation) {
            $this->entities[$realEntityName]['repositoryName']
                = $annotation->repositoryClass;
        }

        return 'FOQ\ElasticaBundle\Repository';
    }

}<commit_msg>Fixed returning custom repository name from annotation<commit_after><?php

namespace FOQ\ElasticaBundle\Manager;

use Doctrine\Common\Annotations\Reader;
use FOQ\ElasticaBundle\Finder\FinderInterface;
use RuntimeException;
/**
 * @author <NAME> <<EMAIL>>
 *
 * Allows retrieval of basic or custom repository for mapped Doctrine
 * entities/documents.
 */
class RepositoryManager implements RepositoryManagerInterface
{
    protected $entities = array();
    protected $repositories = array();
    protected $reader;

    public function __construct(Reader $reader)
    {
        $this->reader = $reader;
    }

    public function addEntity($entityName, FinderInterface $finder, $repositoryName = null)
    {
        $this->entities[$entityName]= array();
        $this->entities[$entityName]['finder'] = $finder;
        $this->entities[$entityName]['repositoryName'] = $repositoryName;
    }

    /**
     * Return repository for entity
     *
     * Returns custom repository if one specified otherwise
     * returns a basic respository.
     */
    public function getRepository($entityName)
    {
        if (isset($this->repositories[$entityName])) {
            return $this->repositories[$entityName];
        }

        if (!isset($this->entities[$entityName])) {
            throw new RuntimeException(sprintf('No search finder configured for %s', $entityName));
        }

        $repositoryName = $this->getRepositoryName($entityName);
        if (!class_exists($repositoryName)) {
            throw new RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $entityName));
        }
        $repository = new $repositoryName($this->entities[$entityName]['finder']);
        $this->repositories[$entityName] = $repository;

        return $repository;
    }

    protected function getRepositoryName($realEntityName)
    {
        if (isset($this->entities[$realEntityName]['repositoryName'])) {
            return $this->entities[$realEntityName]['repositoryName'];
        }

        $refClass   = new \ReflectionClass($realEntityName);
        $annotation = $this->reader->getClassAnnotation($refClass, 'FOQ\\ElasticaBundle\\Configuration\\Search');
        if ($annotation) {
            $this->entities[$realEntityName]['repositoryName']
                = $annotation->repositoryClass;
            return $annotation->repositoryClass;
        }

        return 'FOQ\ElasticaBundle\Repository';
    }

}
{'fraction_non_alphanumeric': 0.1273938384679434, 'fraction_numerical': 0.0, 'mean_word_length': 3.1855400696864113, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, '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': '6174409', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1234, 'n_words': 264}