<commit_before><?php


namespace FS\SolrBundle\Doctrine\Hydration;

use Doctrine\Common\Collections\ArrayCollection;
use FS\SolrBundle\Doctrine\Mapper\MetaInformationInterface;
use FS\SolrBundle\Repository\RepositoryInterface;
use FS\SolrBundle\Solr;
use FS\SolrBundle\Doctrine\Hydration\PropertyAccessor\PrivatePropertyAccessor;

/**
 * Class NoDatabaseRelationHydrator
 *
 * @author <NAME> <<EMAIL>>
 */
class NoDatabaseRelationHydrator implements HydratorInterface
{
    /**
     * @var Solr
     */
    protected $solr;

    /**
     * RelationHydrator constructor.
     *
     * @param Solr $solr
     */
    public function __construct(Solr $solr)
    {
        $this->solr = $solr;
    }

    /**
     * @param object                   $document
     * @param MetaInformationInterface $metaInformation holds the target entity
     *
     * @return object
     */
    public function hydrate($document, MetaInformationInterface $metaInformation)
    {
        $targetEntity = $document;

        $reflectionClass = new \ReflectionClass($targetEntity);

        $relations = $metaInformation->getRelations();

        foreach ($relations as $relation) {
            /** @var \FS\SolrBundle\Doctrine\Annotation\Relation $relation */
            if ($relation->getType() == 'collection') {

                /** @var RepositoryInterface $repository */
                $repository = $this->solr->getRepository($relation->getTarget());
                
                $children = $repository->findByIds((array) $targetEntity->{'get'. ucfirst($relation->name)}());
                $classProperty = $reflectionClass->getProperty($relation->name);
                $accessor = new PrivatePropertyAccessor($classProperty);

                $accessor->setValue($targetEntity, new ArrayCollection($children));
            }
        }

        return $targetEntity;
    }
}<commit_msg>Update NoDatabaseRelationHydrator.php<commit_after><?php


namespace FS\SolrBundle\Doctrine\Hydration;

use Doctrine\Common\Collections\ArrayCollection;
use FS\SolrBundle\Doctrine\Mapper\MetaInformationInterface;
use FS\SolrBundle\Repository\RepositoryInterface;
use FS\SolrBundle\Solr;
use FS\SolrBundle\Doctrine\Hydration\PropertyAccessor\PrivatePropertyAccessor;

/**
 * Class NoDatabaseRelationHydrator
 *
 * @author <NAME> <<EMAIL>>
 */
class NoDatabaseRelationHydrator implements HydratorInterface
{
    /**
     * @var Solr
     */
    protected $solr;

    /**
     * RelationHydrator constructor.
     *
     * @param Solr $solr
     */
    public function __construct(Solr $solr)
    {
        $this->solr = $solr;
    }

    /**
     * @param object                   $document
     * @param MetaInformationInterface $metaInformation holds the target entity
     *
     * @return object
     */
    public function hydrate($document, MetaInformationInterface $metaInformation)
    {
        $targetEntity = $document;

        $reflectionClass = new \ReflectionClass($targetEntity);

        $relations = $metaInformation->getRelations();

        foreach ($relations as $relation) {
            /** @var \FS\SolrBundle\Doctrine\Annotation\Relation $relation */
            $children = $this->solr->getRepository($relation->getTarget())->findBy([
                'parent' => $targetEntity->getId(),
                'type' => $relation->getType()
            ]);

            $classProperty = $reflectionClass->getProperty($relation->name);
            $accessor = new PrivatePropertyAccessor($classProperty);

            $accessor->setValue($targetEntity, new ArrayCollection($children));
        }

        return $targetEntity;
    }
}
{'fraction_non_alphanumeric': 0.11993382961124896, 'fraction_numerical': 0.0, 'mean_word_length': 2.7058222676200203, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 34, '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': '5388807', 'n_tokens_mistral': 1027, 'n_tokens_neox': 971, 'n_words': 175}