<commit_before><?php
namespace Drupal\AppConsole\Console;

use Composer\Autoload\ClassLoader;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug\Debug;

class Application extends BaseApplication
{
    /**
     * @var string
     */
    const NAME = 'Drupal Console';
    /**
     * @var string
     */
    const VERSION = '0.7.6';
    /**
     * @var bool
     */
    protected $booted = false;
    /**
     * @var Drupal\AppConsole\UserConfig
     */
    protected $config;
    /**
     * @var string
     */
    protected $directoryRoot;
    /**
     * @var \Composer\Autoload\ClassLoader
     * The Drupal autoload file.
     */
    protected $drupalAutoload;
    /**
     * @var string
     * The Drupal environment.
     */
    protected $env;
    /**
     * @var bool
     */
    private $commandsRegistered = false;

    private $searchSettingsFile = true;

    /**
     * Create a new application extended from \Symfony\Component\Console\Application.
     *
     * @param $config
     */
    public function __construct($config)
    {
        $this->config = $config;
        $this->env = $config->get('application.environment');

        parent::__construct($this::NAME, sprintf('%s', $this::VERSION));

        $this->getDefinition()->addOption(
          new InputOption('--drupal', '-d', InputOption::VALUE_OPTIONAL, 'Path to Drupal root.')
        );
        $this->getDefinition()->addOption(
          new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.')
        );
        $this->getDefinition()->addOption(
          new InputOption('--env', '-e', InputOption::VALUE_OPTIONAL, 'The Environment name.', $this->env)
        );
        $this->getDefinition()->addOption(
          new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')
        );
        $this->getDefinition()->addOption(
          new InputOption('--learning', null, InputOption::VALUE_NONE, 'Generate a verbose code output.')
        );
    }

    /**
     * {@inheritdoc}
     */
    public function doRun(InputInterface $input, OutputInterface $output)
    {
        $this->isRuningOnDrupalInstance($input);

        if ($this->isBooted()) {
            if ($this->drupalAutoload) {
                $this->initDebug($input);
                $this->doKernelConfiguration();
            }

            if (!$this->commandsRegistered) {
                $this->commandsRegistered = $this->registerCommands();
            }

            if (true === $input->hasParameterOption(array('--shell', '-s'))) {
                $this->runShell($input);
                return 0;
            }
        }

        parent::doRun($input, $output);
    }

    /**
     * @param InputInterface $input
     * @return bool
     */
    protected function isRuningOnDrupalInstance(InputInterface $input)
    {
        $drupal_root = $input->getParameterOption(['--drupal', '-d'], false);

        $auto_load = $this
          ->getHelperSet()
          ->get('drupal-autoload')
          ->findAutoload($drupal_root);

        if (!$this->isSettingsFile()) {
            return false;
        }

        if ($auto_load && !$this->isBooted()) {
            $this->drupalAutoload = require_once $auto_load;
            if ($this->drupalAutoload instanceof ClassLoader) {
                $this->setBooted(true);
                return true;<commit_msg>Change require_once to require when loading the Drupal autoloader, for easier integration with Drush.<commit_after><?php
namespace Drupal\AppConsole\Console;

use Composer\Autoload\ClassLoader;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug\Debug;

class Application extends BaseApplication
{
    /**
     * @var string
     */
    const NAME = 'Drupal Console';
    /**
     * @var string
     */
    const VERSION = '0.7.6';
    /**
     * @var bool
     */
    protected $booted = false;
    /**
     * @var Drupal\AppConsole\UserConfig
     */
    protected $config;
    /**
     * @var string
     */
    protected $directoryRoot;
    /**
     * @var \Composer\Autoload\ClassLoader
     * The Drupal autoload file.
     */
    protected $drupalAutoload;
    /**
     * @var string
     * The Drupal environment.
     */
    protected $env;
    /**
     * @var bool
     */
    private $commandsRegistered = false;

    private $searchSettingsFile = true;

    /**
     * Create a new application extended from \Symfony\Component\Console\Application.
     *
     * @param $config
     */
    public function __construct($config)
    {
        $this->config = $config;
        $this->env = $config->get('application.environment');

        parent::__construct($this::NAME, sprintf('%s', $this::VERSION));

        $this->getDefinition()->addOption(
          new InputOption('--drupal', '-d', InputOption::VALUE_OPTIONAL, 'Path to Drupal root.')
        );
        $this->getDefinition()->addOption(
          new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.')
        );
        $this->getDefinition()->addOption(
          new InputOption('--env', '-e', InputOption::VALUE_OPTIONAL, 'The Environment name.', $this->env)
        );
        $this->getDefinition()->addOption(
          new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')
        );
        $this->getDefinition()->addOption(
          new InputOption('--learning', null, InputOption::VALUE_NONE, 'Generate a verbose code output.')
        );
    }

    /**
     * {@inheritdoc}
     */
    public function doRun(InputInterface $input, OutputInterface $output)
    {
        $this->isRuningOnDrupalInstance($input);

        if ($this->isBooted()) {
            if ($this->drupalAutoload) {
                $this->initDebug($input);
                $this->doKernelConfiguration();
            }

            if (!$this->commandsRegistered) {
                $this->commandsRegistered = $this->registerCommands();
            }

            if (true === $input->hasParameterOption(array('--shell', '-s'))) {
                $this->runShell($input);
                return 0;
            }
        }

        parent::doRun($input, $output);
    }

    /**
     * @param InputInterface $input
     * @return bool
     */
    protected function isRuningOnDrupalInstance(InputInterface $input)
    {
        $drupal_root = $input->getParameterOption(['--drupal', '-d'], false);

        $auto_load = $this
          ->getHelperSet()
          ->get('drupal-autoload')
          ->findAutoload($drupal_root);

        if (!$this->isSettingsFile()) {
            return false;
        }

        if ($auto_load && !$this->isBooted()) {
            $this->drupalAutoload = require $auto_load;
            if ($this->drupalAutoload instanceof ClassLoader) {
                $this->setBooted(true);
                return true;
{'fraction_non_alphanumeric': 0.1446985446985447, 'fraction_numerical': 0.0011088011088011087, 'mean_word_length': 2.1915081822202565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '5973436', 'n_tokens_mistral': 2055, 'n_tokens_neox': 2034, 'n_words': 400}