<commit_before><?php

declare(strict_types = 1);

namespace PHPChunkit;

use PHPChunkit\Command;
use PHPChunkit\GenerateTestClass;
use Pimple\Container as PimpleContainer;
use Symfony\Component\Console\Application;

class Container extends PimpleContainer
{
    public function initialize()
    {
        $this['phpchunkit.configuration'] = $this->getConfiguration();

        $this['phpchunkit.symfony_application'] = function() {
            return new Application();
        };

        $this['phpchunkit.application'] = function() {
            return new PHPChunkitApplication($this);
        };

        $this['phpchunkit.database_sandbox'] = function() {
            return $this['phpchunkit.configuration']->getDatabaseSandbox();
        };

        $this['phpchunkit.event_dispatcher'] = function() {
            return $this['phpchunkit.configuration']->getEventDispatcher();
        };

        $this['phpchunkit.test_chunker'] = function() {
            return new TestChunker($this['phpchunkit.test_counter']);
        };

        $this['phpchunkit.test_runner'] = function() {
            return new TestRunner(
                $this['phpchunkit.symfony_application'],
                $this['phpchunkit.application.input'],
                $this['phpchunkit.application.output'],
                $this['phpchunkit.configuration']
            );
        };

        $this['phpchunkit.test_counter'] = function() {
            return new TestCounter(
                $this['phpchunkit.file_classes_helper']
            );
        };

        $this['phpchunkit.test_finder'] = function() {
            return new TestFinder(
                $this['phpchunkit.configuration']->getTestsDirectory()
            );
        };

        $this['phpchunkit.command.test_watcher'] = function() {
            return new Command\TestWatcher(
                $this['phpchunkit.test_runner'],
                $this['phpchunkit.configuration'],
                $this['phpchunkit.file_classes_helper']
            );
        };

        $this['phpchunkit.command.run'] = function() {
            return new Command\Run(
                $this['phpchunkit.test_runner'],
                $this['phpchunkit.configuration'],
                $this['phpchunkit.test_chunker'],
                $this['phpchunkit.test_finder']
            );
        };

        $this['phpchunkit.command.create_databases'] = function() {
            return new Command\CreateDatabases($this['phpchunkit.event_dispatcher']);
        };

        $this['phpchunkit.command.build_sandbox'] = function() {
            return new Command\BuildSandbox(
                $this['phpchunkit.test_runner'],
                $this['phpchunkit.event_dispatcher']
            );
        };

        $this['phpchunkit.command.generate_test'] = function() {
            return new Command\Generate(new GenerateTestClass());
        };

        $this['phpchunkit.file_classes_helper'] = function() {
            return new FileClassesHelper();
        };
    }

    private function getConfiguration() : Configuration
    {
        $configuration = $this->loadConfiguration();

        $this->loadPHPChunkitBootstrap($configuration);

        // try to guess watch directories
        if (!$configuration->getWatchDirectories()) {
            $paths = [
                sprintf('%s/src', $configuration->getRootDir()),
                sprintf('%s/lib', $configuration->getRootDir()),
                sprintf('%s/tests', $configuration->getRootDir()),
            ];

            $watchDirectories = [];
            foreach ($paths as $path) {
                if (is_dir($path)) {
                    $watchDirectories[] = $path;
                }
            }

            $configuration->setWatchDirectories($watchDirectories);
        }

        // try to guess tests directory
        if (!$configuration->getTestsDirectory()) {
            $paths = [
                sprintf('%s/src', $configuration->getRootDir()),
                sprintf('%s/lib', $configuration->getRootDir()),
                sprintf('%s/tests', $configuration->getRootDir()),
            ];<commit_msg>guest tests dir first.<commit_after><?php

declare(strict_types = 1);

namespace PHPChunkit;

use PHPChunkit\Command;
use PHPChunkit\GenerateTestClass;
use Pimple\Container as PimpleContainer;
use Symfony\Component\Console\Application;

class Container extends PimpleContainer
{
    public function initialize()
    {
        $this['phpchunkit.configuration'] = $this->getConfiguration();

        $this['phpchunkit.symfony_application'] = function() {
            return new Application();
        };

        $this['phpchunkit.application'] = function() {
            return new PHPChunkitApplication($this);
        };

        $this['phpchunkit.database_sandbox'] = function() {
            return $this['phpchunkit.configuration']->getDatabaseSandbox();
        };

        $this['phpchunkit.event_dispatcher'] = function() {
            return $this['phpchunkit.configuration']->getEventDispatcher();
        };

        $this['phpchunkit.test_chunker'] = function() {
            return new TestChunker($this['phpchunkit.test_counter']);
        };

        $this['phpchunkit.test_runner'] = function() {
            return new TestRunner(
                $this['phpchunkit.symfony_application'],
                $this['phpchunkit.application.input'],
                $this['phpchunkit.application.output'],
                $this['phpchunkit.configuration']
            );
        };

        $this['phpchunkit.test_counter'] = function() {
            return new TestCounter(
                $this['phpchunkit.file_classes_helper']
            );
        };

        $this['phpchunkit.test_finder'] = function() {
            return new TestFinder(
                $this['phpchunkit.configuration']->getTestsDirectory()
            );
        };

        $this['phpchunkit.command.test_watcher'] = function() {
            return new Command\TestWatcher(
                $this['phpchunkit.test_runner'],
                $this['phpchunkit.configuration'],
                $this['phpchunkit.file_classes_helper']
            );
        };

        $this['phpchunkit.command.run'] = function() {
            return new Command\Run(
                $this['phpchunkit.test_runner'],
                $this['phpchunkit.configuration'],
                $this['phpchunkit.test_chunker'],
                $this['phpchunkit.test_finder']
            );
        };

        $this['phpchunkit.command.create_databases'] = function() {
            return new Command\CreateDatabases($this['phpchunkit.event_dispatcher']);
        };

        $this['phpchunkit.command.build_sandbox'] = function() {
            return new Command\BuildSandbox(
                $this['phpchunkit.test_runner'],
                $this['phpchunkit.event_dispatcher']
            );
        };

        $this['phpchunkit.command.generate_test'] = function() {
            return new Command\Generate(new GenerateTestClass());
        };

        $this['phpchunkit.file_classes_helper'] = function() {
            return new FileClassesHelper();
        };
    }

    private function getConfiguration() : Configuration
    {
        $configuration = $this->loadConfiguration();

        $this->loadPHPChunkitBootstrap($configuration);

        // try to guess watch directories
        if (!$configuration->getWatchDirectories()) {
            $paths = [
                sprintf('%s/src', $configuration->getRootDir()),
                sprintf('%s/lib', $configuration->getRootDir()),
                sprintf('%s/tests', $configuration->getRootDir()),
            ];

            $watchDirectories = [];
            foreach ($paths as $path) {
                if (is_dir($path)) {
                    $watchDirectories[] = $path;
                }
            }

            $configuration->setWatchDirectories($watchDirectories);
        }

        // try to guess tests directory
        if (!$configuration->getTestsDirectory()) {
            $paths = [
                sprintf('%s/tests', $configuration->getRootDir()),
                sprintf('%s/src', $configuration->getRootDir()),
                sprintf('%s/lib', $configuration->getRootDir()),
            ];
{'fraction_non_alphanumeric': 0.13432474912344336, 'fraction_numerical': 0.00024180872929512756, 'mean_word_length': 2.0378259272860815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '3577710', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2090, 'n_words': 309}