<commit_before><?php

namespace Silktide\Reposition\Sql\Storage;


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

class SqlStorage implements StorageInterface
{

    protected $database;
    protected $builder;
    protected $interpreter;
    protected $hydrator;

    protected $parameters = [];

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

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

    }

    /**
     * @return QueryBuilderInterface
     */
    public function getQueryBuilder()
    {
        return $this->builder;
    }

    /**
     * @param TokenSequencerInterface $query
     * @param string $entityClass
     * @return object
     */
    public function query(TokenSequencerInterface $query, $entityClass)
    {
        $compiledQuery = $this->interpreter->interpret($query);

        $statement = $this->database->prepare($compiledQuery->getQuery());
        $statement->execute($compiledQuery->getArguments());
        $data = $statement->fetchAll(\PDO::FETCH_ASSOC);


<commit_msg>Use the new interpreters in the Storage class<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,
        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)
    {
        $compiledQuery = $this->interpreter->interpret($query);

        $statement = $this->database->prepare($compiledQuery->getQuery());
        $statement->execute($compiledQuery->getArguments());
        $data = $statement->fetchAll(\PDO::FETCH_ASSOC);

        $options = [
            "metadataProvider" => $this->entityMetadataProvider,
            "entityMap" => $query->getIncludes(),
            "entity" => $entityClass
        ];

{'fraction_non_alphanumeric': 0.11060142711518858, 'fraction_numerical': 0.0, 'mean_word_length': 3.2295258620689653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '211110', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1053, 'n_words': 180}