<commit_before><?php declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\SQLLogger;
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;

/**
 * This class is caches queries so that they can be run as quickly as possible on subsequent builds
 *
 * @see \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures\FixturesHelper::createDb
 */
class QueryCachingLogger implements SQLLogger
{
    private $queries = [];

    public function startQuery($sql, array $params = null, array $types = null)
    {
        $this->queries[$sql][] = [$params, $types];
    }

    public function stopQuery()
    {
        return;
    }

    public function run(Connection $connection): void
    {
        foreach ($this->queries as $query => $paramsArray) {
            if ('"START TRANSACTION"' === $query) {
                $connection->beginTransaction();
                continue;
            }
            if ('"COMMIT"' === $query) {
                $connection->commit();
                continue;
            }
            if ([[[], []]] === $paramsArray) {
                $connection->prepare($query)->execute();
                continue;
            }
            $stmt = $connection->prepare($query);
            foreach ($paramsArray as $paramsTypes) {
                try {
                    list($params, $types) = $paramsTypes;
                    $colNum = 1;
                    foreach ($params as $key => $value) {
                        $stmt->bindValue($colNum++, $value, $types[$key]);
                    }
                    $stmt->execute();
                } catch (\Exception $e) {
                    if ($connection->isTransactionActive()) {
                        $connection->rollBack();
                    }
                    throw new DoctrineStaticMetaException(
                        'Failed running logged query ' . $query . 'with params and types: '
                        . print_r($paramsTypes, true),
                        $e->getCode(),
                        $e
                    );
                }
            }
        }
    }
}
<commit_msg>dont log ping queries<commit_after><?php declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\SQLLogger;
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;

/**
 * This class is caches queries so that they can be run as quickly as possible on subsequent builds
 *
 * @see \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures\FixturesHelper::createDb
 */
class QueryCachingLogger implements SQLLogger
{
    private $queries = [];

    public function startQuery($sql, array $params = null, array $types = null)
    {
        $this->queries[$sql][] = [$params, $types];
    }

    public function stopQuery()
    {
        return;
    }

    public function run(Connection $connection): void
    {
        foreach ($this->queries as $query => $paramsArray) {
            if ('"START TRANSACTION"' === $query) {
                $connection->beginTransaction();
                continue;
            }
            if ('"COMMIT"' === $query) {
                $connection->commit();
                continue;
            }
            if ('"SELECT 1"' == $query) {
                //this is a ping query
                continue;
            }
            if ([[[], []]] === $paramsArray) {
                $connection->prepare($query)->execute();
                continue;
            }
            $stmt = $connection->prepare($query);
            foreach ($paramsArray as $paramsTypes) {
                try {
                    list($params, $types) = $paramsTypes;
                    $colNum = 1;
                    foreach ($params as $key => $value) {
                        $stmt->bindValue($colNum++, $value, $types[$key]);
                    }
                    $stmt->execute();
                } catch (\Exception $e) {
                    if ($connection->isTransactionActive()) {
                        $connection->rollBack();
                    }
                    throw new DoctrineStaticMetaException(
                        'Failed running logged query ' . $query . 'with params and types: '
                        . print_r($paramsTypes, true),
                        $e->getCode(),
                        $e
                    );
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.12053473591935131, 'fraction_numerical': 0.0010957703265395574, 'mean_word_length': 1.5257332595462092, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '2135385', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1118, 'n_words': 253}