<commit_before><?php
namespace kahlan\analysis;

use Exception;
use ReflectionClass;
use string\String;

/**
 * The `Debugger` class provides basic facilities for generating and rendering meta-data about the
 * state of an application in its current context.
 */
class Debugger
{
    /**
     * Store the autoloader
     */
    public static $_loader = null;

    /**
     * Gets a backtrace string based on the supplied options.
     *
     * @param  array $options Format for outputting stack trace. Available options are:
     *                        - `'start'`: The depth to start with.
     *                        - `'depth'`: The maximum depth of the trace.
     *                        - `'message'`: Either `null` for default message or a string.
     *                        - `'trace'`: A trace to use instead of generating one.
     * @return array          The formatted backtrace.
     */
    public static function trace($options = [])
    {
        $defaults = ['trace' => []];
        $options += $defaults;
        $back = [];
        $backtrace = static::backtrace($options);
        $error = reset($backtrace);

        foreach ($backtrace as $trace) {
            $back[] =  static::_traceToString($trace);
        }
        return join("\n", $back);
    }

    /**
     * Gets a string representation of a trace.
     *
     * @param  array  $trace A trace array.
     * @return string The string representation of a trace.
     */
    protected static function _traceToString($trace)
    {
        $loader = static::loader();

        if (!empty($trace['class'])) {
            $trace['function'] = $trace['class'] . '::' . $trace['function'] . '()';
        } else {
            $line = static::_line($trace);
            $trace['line'] = $line !== $trace['line'] ? $line . ' to ' . $trace['line'] : $trace['line'];
        }

        if (preg_match("/eval\(\)'d code/", $trace['file']) && $trace['class'] && $loader) {
            $trace['file'] = $loader->findFile($trace['class']);
        }

        if (strpos($trace['function'], '{closure}') !== false) {
            $trace['function'] = "{closure}";
        }
        return $trace['function'] .' - ' . $trace['file'] . ', line ' . $trace['line'];
    }

    /**
     * Return a backtrace array based on the supplied options.<commit_msg>Removed unused $error in Debugger; Commented code that never will be fired;<commit_after><?php
namespace kahlan\analysis;

use Exception;
use ReflectionClass;
use string\String;

/**
 * The `Debugger` class provides basic facilities for generating and rendering meta-data about the
 * state of an application in its current context.
 */
class Debugger
{
    /**
     * Store the autoloader
     */
    public static $_loader = null;

    /**
     * Gets a backtrace string based on the supplied options.
     *
     * @param  array $options Format for outputting stack trace. Available options are:
     *                        - `'start'`: The depth to start with.
     *                        - `'depth'`: The maximum depth of the trace.
     *                        - `'message'`: Either `null` for default message or a string.
     *                        - `'trace'`: A trace to use instead of generating one.
     * @return array          The formatted backtrace.
     */
    public static function trace($options = [])
    {
        $defaults = ['trace' => []];
        $options += $defaults;
        $back = [];
        $backtrace = static::backtrace($options);

        foreach ($backtrace as $trace) {
            $back[] =  static::_traceToString($trace);
        }
        return join("\n", $back);
    }

    /**
     * Gets a string representation of a trace.
     *
     * @param  array  $trace A trace array.
     * @return string The string representation of a trace.
     */
    protected static function _traceToString($trace)
    {
        $loader = static::loader();

        if (!empty($trace['class'])) {
            $trace['function'] = $trace['class'] . '::' . $trace['function'] . '()';
        } else {
            $line = static::_line($trace);
            $trace['line'] = $line !== $trace['line'] ? $line . ' to ' . $trace['line'] : $trace['line'];
        }

        if (preg_match("/eval\(\)'d code/", $trace['file']) && $trace['class'] && $loader) {
            $trace['file'] = $loader->findFile($trace['class']);
        }

        // This code will never fire, because of backtrace closure checking
        // Please check this!
        // if (strpos($trace['function'], '{closure}') !== false) {
        //     $trace['function'] = "{closure}";
        // }
        return $trace['function'] .' - ' . $trace['file'] . ', line ' . $trace['line'];
    }

    /**
     * Return a backtrace array based on the supplied options.
{'fraction_non_alphanumeric': 0.1556298307917276, 'fraction_numerical': 0.0, 'mean_word_length': 2.0246367656348707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3796753', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1295, 'n_words': 395}