<commit_before><?php

namespace Silktide\Reposition\Sql\Storage;


use Silktide\Reposition\Hydrator\HydratorInterface;
use Silktide\Reposition\Metadata\EntityMetadataProviderInterface;
use Silktide\Reposition\Normaliser\NormaliserInterface;
use Silktide\Reposition\QueryBuilder\TokenSequencerInterface;
use Silktide\Reposition\Sql\QueryInterpreter\SqlQueryInterpreter;
use Silktide\Reposition\Storage\StorageInterface;

class SqlStorage implements StorageInterface
{

    protected $database;
    protected $interpreter;
    protected $entityMetadataProvider;
    protected $hydrator;

    protected $parameters = [];

    public function __construct(
        PdoAdapter $database,
        SqlQueryInterpreter $interpreter,
        EntityMetadataProviderInterface $entityMetadataProvider,
        HydratorInterface $hydrator = null,
        NormaliserInterface $normaliser = null
    ) {
        $this->database = $database;
        $this->interpreter = $interpreter;
        $this->entityMetadataProvider = $entityMetadataProvider;
        $this->hydrator = $hydrator;

        $this->interpreter->setEntityMetadataProvider($this->entityMetadataProvider);

        if (!empty($normaliser)) {
            $this->interpreter->setNormaliser($normaliser);
            if (!empty($hydrator)) {
                $this->hydrator->setNormaliser($normaliser);
            }
        }

    }

    /**
     * @param TokenSequencerInterface $query
     * @param string $entityClass
     * @return object
     */
    public function query(TokenSequencerInterface $query, $entityClass)<commit_msg>Injecting a metadata provider into the SqlStorage instance can cause a circular dependency if it is also the default storage. Instead, the RepositoryManager will inject itself into the storage instance when available<commit_after><?php

namespace Silktide\Reposition\Sql\Storage;


use Silktide\Reposition\Hydrator\HydratorInterface;
use Silktide\Reposition\Metadata\EntityMetadataProviderInterface;
use Silktide\Reposition\Normaliser\NormaliserInterface;
use Silktide\Reposition\QueryBuilder\TokenSequencerInterface;
use Silktide\Reposition\Sql\QueryInterpreter\SqlQueryInterpreter;
use Silktide\Reposition\Storage\StorageInterface;

class SqlStorage implements StorageInterface
{

    protected $database;
    protected $interpreter;
    protected $entityMetadataProvider;
    protected $hydrator;

    protected $parameters = [];

    public function __construct(
        PdoAdapter $database,
        SqlQueryInterpreter $interpreter,
        HydratorInterface $hydrator = null,
        NormaliserInterface $normaliser = null
    ) {
        $this->database = $database;
        $this->interpreter = $interpreter;
        $this->hydrator = $hydrator;

        if (!empty($normaliser)) {
            $this->interpreter->setNormaliser($normaliser);
            if (!empty($hydrator)) {
                $this->hydrator->setNormaliser($normaliser);
            }
        }

    }

    public function setEntityMetadataProvider(EntityMetadataProviderInterface $provider)
    {
        $this->entityMetadataProvider = $provider;
        $this->interpreter->setEntityMetadataProvider($this->entityMetadataProvider);
    }

    public function hasEntityMetadataProvider()
    {
        return !empty($this->entityMetadataProvider);
    }

    /**
     * @param TokenSequencerInterface $query
     * @param string $entityClass
     * @return object
     */
    public function query(TokenSequencerInterface $query, $entityClass)
{'fraction_non_alphanumeric': 0.0901312036508842, 'fraction_numerical': 0.0, 'mean_word_length': 3.6023622047244093, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '4481869', 'n_tokens_mistral': 933, 'n_tokens_neox': 907, 'n_words': 181}