<commit_before><?php

namespace Represent\Builder;

use Doctrine\ORM\EntityManager;

class DoctrineGenericBuilder extends GenericRepresentationBuilder
{
    /**
     * @var EntityManager
     */
    private $em;

    public function __construct(PropertyContextBuilder $propertyBuilder, ClassContextBuilder $classBuilder, EntityManager $em)
    {
        $this->propertyBuilder = $propertyBuilder;
        $this->classBuilder    = $classBuilder;
        $this->em              = $em;
    }

    protected function handleObject($object, $view)
    {
        if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
            $object = $this->em->find(get_class($object), $object->getPrimaryKey());
        }

        return parent::handleObject($object, $view);
    }
}<commit_msg>update the doctrine workaround<commit_after><?php

namespace Represent\Builder;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;

class DoctrineGenericBuilder extends GenericRepresentationBuilder
{
    /**
     * @var EntityManager
     */
    private $em;

    public function __construct(PropertyContextBuilder $propertyBuilder, ClassContextBuilder $classBuilder, EntityManager $em)
    {
        $this->propertyBuilder = $propertyBuilder;
        $this->classBuilder    = $classBuilder;
        $this->em              = $em;
    }

    protected function handleObject($object, $view)
    {
        if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
            $object = $this->handleDoctrineProxy($object);
        }

        $hash   = spl_object_hash($object);
        $check  = array_search($hash, $this->visited);
        $output = new \stdClass();

        if ($check !== false) {
            $output = new \stdClass();
            $rel    = '$rel';
            $output->$rel = $check;

            return $output;
        }
        $output->_hash = count($this->visited);
        $this->visited[] = $hash;
        $reflection      = new \ReflectionClass($object);
        $classContext    = $this->classBuilder->buildClassContext($reflection, $hash, $view);

        foreach ($classContext->properties as $property) {
            $output = $this->handleProperty($property, $object, $output, $classContext);
        }

        return $output;
    }

    private function handleDoctrineProxy(\Doctrine\ORM\Proxy\Proxy $proxy)
    {
        do {
            $this->em->detach($proxy);
            $object = $this->em->find(get_class($proxy), $proxy->getPrimaryKey());
            $this->em->merge($object);
        } while ($object instanceof \Doctrine\ORM\Proxy\Proxy);

        return $object;
    }
}
{'fraction_non_alphanumeric': 0.13145720894371626, 'fraction_numerical': 0.0, 'mean_word_length': 2.525815217391304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '5929225', 'n_tokens_mistral': 717, 'n_tokens_neox': 704, 'n_words': 141}