<commit_before><?php

namespace OpenConext\Component\EngineBlockMetadata\MetadataRepository;

use OpenConext\Component\EngineBlockMetadata\Container\ContainerInterface;
use OpenConext\Component\EngineBlockMetadata\Entity\AbstractRole;
use OpenConext\Component\EngineBlockMetadata\Entity\IdentityProvider;
use OpenConext\Component\EngineBlockMetadata\Entity\ServiceProvider;
use OpenConext\Component\EngineBlockMetadata\Entity\Assembler\StokerAssembler;
use OpenConext\Component\StokerMetadata\MetadataEntitySource;
use OpenConext\Component\StokerMetadata\MetadataIndex;

/**
 * Class StokerMetadataRepository
 * @package OpenConext\Component\EngineBlockMetadata\MetadataRepository
 * @SuppressWarnings(PMD.TooManyMethods)
 * @SuppressWarnings(PMD.CouplingBetweenObjects)
 */
class StokerMetadataRepository extends AbstractMetadataRepository
{
    /**
     * @var StokerAssembler
     */
    private $translator;

    /**
     * @var MetadataEntitySource
     */
    private $metadataEntitySource;

    /**
     * @var MetadataIndex
     */
    private $metadataIndex;

    /**
     * @param array $repositoryConfig
     * @param ContainerInterface $container
     * @return mixed|static
     * @throws \RuntimeException
     */
    public static function createFromConfig(array $repositoryConfig, ContainerInterface $container)
    {
        if (!isset($repositoryConfig['path'])) {
            throw new \RuntimeException('No path configured for stoker repository');
        }
        return new static($repositoryConfig['path'], new StokerAssembler());
    }

    /**
     * @param string $metadataDirectory
     * @param \OpenConext\Component\EngineBlockMetadata\Entity\Assembler\StokerAssembler $assembler
     * @throws \RuntimeException
     */
    public function __construct($metadataDirectory, StokerAssembler $assembler)
    {
        parent::__construct();

        $this->metadataEntitySource = new MetadataEntitySource($metadataDirectory);
        $this->metadataIndex = MetadataIndex::load($metadataDirectory);
        if (!$this->metadataIndex) {
            throw new \RuntimeException(
                "Unable to load $metadataDirectory" . DIRECTORY_SEPARATOR . MetadataIndex::FILENAME
            );
        }
        $this->metadataDirectory = $metadataDirectory;
        $this->translator = $assembler;
    }

    /**
     *
     * @param string $entityId
     * @return AbstractRole
     * @throws EntityNotFoundException
     */
    public function fetchEntityByEntityId($entityId)
    {
        $metadataIndexEntity = $this->metadataIndex->getEntityByEntityId($entityId);
        if (!$metadataIndexEntity) {
            throw new EntityNotFoundException("Unable to find entity in the index");<commit_msg>Make StokerMetadataRepository more testable<commit_after><?php

namespace OpenConext\Component\EngineBlockMetadata\MetadataRepository;

use OpenConext\Component\EngineBlockMetadata\Container\ContainerInterface;
use OpenConext\Component\EngineBlockMetadata\Entity\AbstractRole;
use OpenConext\Component\EngineBlockMetadata\Entity\IdentityProvider;
use OpenConext\Component\EngineBlockMetadata\Entity\ServiceProvider;
use OpenConext\Component\EngineBlockMetadata\Entity\Assembler\StokerAssembler;
use OpenConext\Component\StokerMetadata\MetadataEntitySource;
use OpenConext\Component\StokerMetadata\MetadataIndex;

/**
 * Class StokerMetadataRepository
 * @package OpenConext\Component\EngineBlockMetadata\MetadataRepository
 * @SuppressWarnings(PMD.TooManyMethods)
 * @SuppressWarnings(PMD.CouplingBetweenObjects)
 */
class StokerMetadataRepository extends AbstractMetadataRepository
{
    /**
     * @var StokerAssembler
     */
    private $translator;

    /**
     * @var MetadataEntitySource
     */
    private $metadataEntitySource;

    /**
     * @var MetadataIndex
     */
    private $metadataIndex;

    /**
     * @param array $repositoryConfig
     * @param ContainerInterface $container
     * @return mixed|static
     * @throws \RuntimeException
     */
    public static function createFromConfig(array $repositoryConfig, ContainerInterface $container)
    {
        if (!isset($repositoryConfig['path'])) {
            throw new \RuntimeException('No path configured for stoker repository');
        }
        $directory = $repositoryConfig['path'];

        $entitySource = new MetadataEntitySource($directory);

        $index = MetadataIndex::load($directory);
        if (!$index) {
            throw new \RuntimeException(
                "Unable to load $directory" . DIRECTORY_SEPARATOR . MetadataIndex::FILENAME
            );
        }

        $assembler = new StokerAssembler();

        return new static($entitySource, $index, $directory, $assembler);
    }

    /**
     * @param MetadataEntitySource $source
     * @param MetadataIndex $index
     * @param $directory
     * @param StokerAssembler $assembler
     */
    public function __construct(
        MetadataEntitySource $source,
        MetadataIndex $index,
        $directory,
        StokerAssembler $assembler
    ) {
        parent::__construct();

        $this->metadataEntitySource = $source;
        $this->metadataIndex = $index;
        $this->metadataDirectory = $directory;
        $this->translator = $assembler;
    }

    /**
     *
     * @param string $entityId
     * @return AbstractRole
     * @throws EntityNotFoundException
     */
    public function fetchEntityByEntityId($entityId)
    {
        $metadataIndexEntity = $this->metadataIndex->getEntityByEntityId($entityId);
        if (!$metadataIndexEntity) {
            throw new EntityNotFoundException("Unable to find entity in the index");
{'fraction_non_alphanumeric': 0.09698581560283688, 'fraction_numerical': 0.0, 'mean_word_length': 3.4452324665090623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '2269405', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1468, 'n_words': 276}