<commit_before><?php

namespace Bolt\Debug;

use Bolt\Version;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug;

/**
 * Shutdown handler set up.
 *
 * @author <NAME> <<EMAIL>>
 */
class ShutdownHandler
{
    /**
     * Set the handlers.
     *
     * @param bool $debug
     */
    public static function register($debug = true)
    {
        $errorLevels = error_reporting();
        if ($debug) {
            $errorLevels |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
            Debug\DebugClassLoader::enable();
        }

        if (PHP_SAPI !== 'cli') {
            Debug\ErrorHandler::register()->throwAt($errorLevels, true);
            Debug\ExceptionHandler::register($debug);
        } else {
            $consoleHandler = function (\Exception $e) {
                $app = new Application('Bolt CLI', Version::VERSION);
                $output = new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG);
                $app->renderException($e, $output);
                ob_clean();
            };
            Debug\ExceptionHandler::register($debug)->setHandler($consoleHandler);
        }
    }
}<commit_msg>When debugging is enabled, call Debug::enable()<commit_after><?php

namespace Bolt\Debug;

use Bolt\Version;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug;

/**
 * Shutdown handler set up.
 *
 * @author <NAME> <<EMAIL>>
 */
class ShutdownHandler
{
    public static $errorLevels;

    /**
     * Set the handlers.
     *
     * NOTE:
     * CLI uses a custom output handler & must NOT call Debug::enable() as this
     * breaks Codeception redirect handling under some circumstances.
     *
     * @param bool $debug
     */
    public static function register($debug = true)
    {
        self::$errorLevels = error_reporting();

        if (PHP_SAPI === 'cli') {
            $consoleHandler = function (\Exception $e) {
                $app = new Application('Bolt CLI', Version::VERSION);
                $output = new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG);
                $app->renderException($e, $output);
                ob_clean();
            };
            Debug\ExceptionHandler::register($debug)->setHandler($consoleHandler);

            return;
        }

        if ($debug) {
            self::$errorLevels |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
        }
        Debug\Debug::enable(self::$errorLevels, true);
        Debug\ExceptionHandler::register($debug);
    }
}
{'fraction_non_alphanumeric': 0.12463450292397661, 'fraction_numerical': 0.0, 'mean_word_length': 2.5407503234152653, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, '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': '5911975', 'n_tokens_mistral': 785, 'n_tokens_neox': 758, 'n_words': 159}