<commit_before><?php

namespace LastCall\Crawler\Command;

use LastCall\Crawler\Crawler;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * Console command to execute setup and teardown tasks.
 */
class SetupTeardownCommand extends CrawlerCommand
{
    private $tearsDown = true;
    private $setsUp = true;

    /**
     * Create a new instance of the command, configured for setup only.
     *
     * @return static
     */
    public static function setup()
    {
        return new static('setup', false, true,
            'Sets up the crawler for a new session.');
    }

    /**
     * Create a new instance of the command, configured for teardown only.
     *
     * @return static
     */
    public static function teardown()
    {
        return new static('teardown', true, false, 'Tears down the crawler.');
    }

    /**
     * Create a new instance of the command, configured for setup and teardown.
     *
     * @return static
     */
    public static function reset()
    {
        return new static('reset', true, true,
            'Reset the crawler session and prepare it for a new run.');
    }

    /**
     * SetupTeardownCommand constructor.
     *
     * @param null   $name
     * @param bool   $tearsDown
     * @param bool   $setsUp
     * @param string $description
     */
    public function __construct(
        $name,
        $tearsDown = true,
        $setsUp = true,
        $description = ''
    ) {
        $this->setDescription($description);
        parent::__construct($name);
        $this->tearsDown = $tearsDown;
        $this->setsUp = $setsUp;
    }

    /**
     * {@inheritdoc}
     */
    public function configure()
    {
        $this->addArgument('filename', InputArgument::OPTIONAL, 'Path to a configuration file.', 'crawler.php');
    }

    /**
     * {@inheritdoc}
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $config = $this->getConfiguration($input->getArgument('filename'));
        $this->prepareConfiguration($config, $input, $output);
        $dispatcher = new EventDispatcher();
        $this->prepareDispatcher($config, $dispatcher, $input, $output);

        $crawler = new Crawler($dispatcher, $config->getClient(), $config->getQueue());

        if ($this->tearsDown) {
            $crawler->teardown();
        }
        if ($this->setsUp) {
            $crawler->setup();
        }
    }
}<commit_msg>Use CrawlerCommand::getCrawler() in SetupTeardownCommand<commit_after><?php

namespace LastCall\Crawler\Command;

use LastCall\Crawler\Crawler;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * Console command to execute setup and teardown tasks.
 */
class SetupTeardownCommand extends CrawlerCommand
{
    private $tearsDown = true;
    private $setsUp = true;

    /**
     * Create a new instance of the command, configured for setup only.
     *
     * @return static
     */
    public static function setup()
    {
        return new static('setup', false, true,
            'Sets up the crawler for a new session.');
    }

    /**
     * Create a new instance of the command, configured for teardown only.
     *
     * @return static
     */
    public static function teardown()
    {
        return new static('teardown', true, false, 'Tears down the crawler.');
    }

    /**
     * Create a new instance of the command, configured for setup and teardown.
     *
     * @return static
     */
    public static function reset()
    {
        return new static('reset', true, true,
            'Reset the crawler session and prepare it for a new run.');
    }

    /**
     * SetupTeardownCommand constructor.
     *
     * @param null   $name
     * @param bool   $tearsDown
     * @param bool   $setsUp
     * @param string $description
     */
    public function __construct(
        $name,
        $tearsDown = true,
        $setsUp = true,
        $description = ''
    ) {
        $this->setDescription($description);
        parent::__construct($name);
        $this->tearsDown = $tearsDown;
        $this->setsUp = $setsUp;
    }

    /**
     * {@inheritdoc}
     */
    public function configure()
    {
        $this->addArgument('filename', InputArgument::OPTIONAL, 'Path to a configuration file.', 'crawler.php');
    }

    /**
     * {@inheritdoc}
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $config = $this->getConfiguration($input->getArgument('filename'));
        $this->prepareConfiguration($config, $input, $output);
        $dispatcher = new EventDispatcher();
        $this->prepareDispatcher($config, $dispatcher, $input, $output);

        $crawler = $this->getCrawler($config, $dispatcher);

        if ($this->tearsDown) {
            $crawler->teardown();
        }
        if ($this->setsUp) {
            $crawler->setup();
        }
    }
}
{'fraction_non_alphanumeric': 0.1224764468371467, 'fraction_numerical': 0.0, 'mean_word_length': 2.4022236756049704, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '4315681', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1473, 'n_words': 385}