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

use ApiClients\Foundation\Hydrator\Factory;
use ApiClients\Foundation\Hydrator\Hydrator;
use ApiClients\Foundation\Hydrator\Options;
use GeneratedHydrator\Configuration;

abstract class AbstractBench
{
    private $tmpDir = '';
    private $tmpNamespace = '';

    protected $hydrator;
    protected $hydratorNoCache;

    public function init()
    {
        $this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('wyrihaximus-php-api-client-tests-') . DIRECTORY_SEPARATOR;
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            $this->tmpDir = 'C:\\t\\';
        }
        mkdir($this->tmpDir, 0777, true);
        $this->tmpNamespace = Configuration::DEFAULT_GENERATED_CLASS_NAMESPACE . uniqid('WHPACTN');

        $this->hydrator = $this->createHydrator();
        $this->hydratorNoCache = $this->createNoCacheHydrator();
    }

    protected function createHydrator(): Hydrator
    {
        return Factory::create([
            Options::NAMESPACE => 'ApiClients\Tests\Foundation\Hydrator\Resources',
            Options::NAMESPACE_SUFFIX => 'Sync',
            Options::RESOURCE_CACHE_DIR => $this->getTmpDir(),
            Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(),
        ]);
    }

    protected function createNoCacheHydrator(): Hydrator
    {
        return Factory::create([
            Options::NAMESPACE => 'ApiClients\Tests\Foundation\Hydrator\Resources',
            Options::NAMESPACE_SUFFIX => 'Sync',
            Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(),
        ]);
    }

    public function cleanup()
    {
        $this->rmdir($this->tmpDir);
    }

    protected function getTmpDir(): string
    {
        return $this->tmpDir;
    }

    protected function getRandomNameSpace(): string
    {
        return $this->tmpNamespace;
    }

    protected function rmdir($dir)
    {
        $directory = dir($dir);
        while (false !== ($entry = $directory->read())) {
            if (in_array($entry, ['.', '..'])) {
                continue;
            }

            if (is_dir($dir . $entry)) {
                $this->rmdir($dir . $entry . DIRECTORY_SEPARATOR);
                continue;
            }

            if (is_file($dir . $entry)) {
                unlink($dir . $entry);
                continue;
            }
        }
        $directory->close();
        rmdir($dir);
    }
}<commit_msg>Fixed benchmark<commit_after><?php declare(strict_types=1);

use ApiClients\Foundation\Hydrator\Factory;
use ApiClients\Foundation\Hydrator\Hydrator;
use ApiClients\Foundation\Hydrator\Options;
use GeneratedHydrator\Configuration;
use League\Container\Container;
use League\Event\Emitter;
use League\Event\EmitterInterface;
use League\Tactician\CommandBus;
use League\Tactician\Setup\QuickStart;

abstract class AbstractBench
{
    private $tmpDir = '';
    private $tmpNamespace = '';

    protected $hydrator;
    protected $hydratorNoCache;

    public function init()
    {
        $this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('wyrihaximus-php-api-client-tests-') . DIRECTORY_SEPARATOR;
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            $this->tmpDir = 'C:\\t\\';
        }
        mkdir($this->tmpDir, 0777, true);
        $this->tmpNamespace = Configuration::DEFAULT_GENERATED_CLASS_NAMESPACE . uniqid('WHPACTN');

        $this->hydrator = $this->createHydrator();
        $this->hydratorNoCache = $this->createNoCacheHydrator();
    }

    protected function createHydrator(): Hydrator
    {
        $container = new Container();
        $container->share(EmitterInterface::class, new Emitter());
        $container->share(CommandBus::class, QuickStart::create([]));
        return Factory::create(
            $container,
            [
                Options::NAMESPACE => 'ApiClients\Tests\Foundation\Hydrator\Resources',
                Options::NAMESPACE_SUFFIX => 'Sync',
                Options::RESOURCE_CACHE_DIR => $this->getTmpDir(),
                Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(),
            ]
        );
    }

    protected function createNoCacheHydrator(): Hydrator
    {
        $container = new Container();
        $container->share(EmitterInterface::class, new Emitter());
        $container->share(CommandBus::class, QuickStart::create([]));
        return Factory::create(
            $container,
            [
                Options::NAMESPACE => 'ApiClients\Tests\Foundation\Hydrator\Resources',
                Options::NAMESPACE_SUFFIX => 'Sync',
                Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(),
            ]
        );
    }

    public function cleanup()
    {
        $this->rmdir($this->tmpDir);
    }

    protected function getTmpDir(): string
    {
        return $this->tmpDir;
    }

    protected function getRandomNameSpace(): string
    {
        return $this->tmpNamespace;
    }

    protected function rmdir($dir)
    {
        $directory = dir($dir);
        while (false !== ($entry = $directory->read())) {
            if (in_array($entry, ['.', '..'])) {
                continue;
            }

            if (is_dir($dir . $entry)) {
                $this->rmdir($dir . $entry . DIRECTORY_SEPARATOR);
                continue;
            }

            if (is_file($dir . $entry)) {
                unlink($dir . $entry);
                continue;
            }
        }
        $directory->close();
        rmdir($dir);
    }
}
{'fraction_non_alphanumeric': 0.13869273945319574, 'fraction_numerical': 0.0025348542458808617, 'mean_word_length': 2.278338278931751, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '2857109', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1603, 'n_words': 259}