<commit_before><?php
/**
 * @link       http://zoopcommerce.github.io/shard
 * @package    Zoop
 * @license    MIT
 */
namespace Zoop\Shard\Rest;

/**
 *
 * @since   1.0
 * @author  <NAME> <<EMAIL>>
 */
class EndpointMap
{
    protected $map = [];

    public function setMap($map)
    {
        $this->map = $map;
    }

    public function hasEndpoint($name)
    {
        return array_key_exists($name, $this->map);
    }

    public function getEndpoint($name)
    {
        if (! $this->hasEndpoint($name)) {
            return;
        }
        $endpoint = $this->map[$name];
        if (! $endpoint instanceof Endpoint) {
            $endpoint = new Endpoint($endpoint);
            $endpoint->setName($name);
            $this->map[$name] = $endpoint;
        }
        return $endpoint;
    }

    public function getEndpointsFromClass($class)
    {
        $result = [];

        $checkEmbeddedEndpoints = function ($endpoint) use (&$result, $class, &$checkEmbeddedEndpoints) {
            $embeddedLists = $endpoint->getEmbeddedLists();
            if (count($embeddedLists) > 0) {
                foreach ($embeddedLists as $name => $embeddedEndpoint) {
                    if ($embeddedEndpoint->getClass() == $class) {
                        $result[] = $embeddedEndpoint;
                    }
                    $checkEmbeddedEndpoints($embeddedEndpoint);
                }
            }
        };

        foreach ($this->map as $name => $endpoint) {
            $endpoint = $this->getEndpoint($name);
            if ($endpoint->getClass() == $class) {
                $result[] = $endpoint;
            }
            $checkEmbeddedEndpoints($endpoint);
        }<commit_msg>Let endpoint map look handle document inheritance<commit_after><?php
/**
 * @link       http://zoopcommerce.github.io/shard
 * @package    Zoop
 * @license    MIT
 */
namespace Zoop\Shard\Rest;

use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;

/**
 *
 * @since   1.0
 * @author  <NAME> <<EMAIL>>
 */
class EndpointMap
{
    protected $map = [];

    public function setMap($map)
    {
        $this->map = $map;
    }

    public function hasEndpoint($name)
    {
        return array_key_exists($name, $this->map);
    }

    public function getEndpoint($name)
    {
        if (! $this->hasEndpoint($name)) {
            return;
        }
        $endpoint = $this->map[$name];
        if (! $endpoint instanceof Endpoint) {
            $endpoint = new Endpoint($endpoint);
            $endpoint->setName($name);
            $this->map[$name] = $endpoint;
        }
        return $endpoint;
    }

    public function getEndpointsFromMetadata(ClassMetadata $metadata)
    {
        $result = [];

        $class = $metadata->name;

        $checkEmbeddedEndpoints = function ($endpoint) use (&$result, $class, &$checkEmbeddedEndpoints) {
            $embeddedLists = $endpoint->getEmbeddedLists();
            if (count($embeddedLists) > 0) {
                foreach ($embeddedLists as $name => $embeddedEndpoint) {
                    if ($embeddedEndpoint->getClass() == $class) {
                        $result[] = $embeddedEndpoint;
                    }
                    $checkEmbeddedEndpoints($embeddedEndpoint);
                }
            }
        };

        foreach ($this->map as $name => $endpoint) {
            $endpoint = $this->getEndpoint($name);
            if ($endpoint->getClass() == $class) {
                $result[] = $endpoint;
            }
            if (isset($metadata->parentClasses)){
                foreach ($metadata->parentClasses as $parentClass){
                    if ($endpoint->getClass() == $parentClass) {
                        $result[] = $endpoint;
                    }
                }
            }
            $checkEmbeddedEndpoints($endpoint);
        }
{'fraction_non_alphanumeric': 0.14046121593291405, 'fraction_numerical': 0.0015723270440251573, 'mean_word_length': 1.7460431654676258, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '5306564', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1015, 'n_words': 200}