<commit_before><?php
/*
 * This file is part of the PHP_CodeCoverage package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Driver for Phpdbg's code coverage functionality.
 *
 * @since Class available since Release 2.2.0
 * @codeCoverageIgnore
 */
class PHP_CodeCoverage_Driver_Phpdbg implements PHP_CodeCoverage_Driver
{
    /**
     * Constructor.
     */
    public function __construct()
    {
        if (PHP_SAPI !== 'phpdbg') {
            throw new PHP_CodeCoverage_Exception('This driver requires the phpdbg sapi');
        }

        if (version_compare(phpversion(), '7.0', '<')) {
            // actually we require the phpdbg version shipped with php7, not php7 itself
            throw new PHP_CodeCoverage_Exception(
                'phpdbg based code coverage requires at least php7'
            );
        }
    }

    /**
     * Start collection of code coverage information.
     */
    public function start()
    {
       phpdbg_start_oplog();
    }

    /**
     * Stop collection of code coverage information.
     *
     * @return array
     */
    public function stop()
    {
        $dbgData = phpdbg_end_oplog();

        $sourceLines = phpdbg_get_executable();
        foreach ($sourceLines as &$lines) {
            foreach ($lines as &$line) {
                $line = self::LINE_NOT_EXECUTED;
            }
        }

        $data = $this->detectExecutedLines($sourceLines, $dbgData);
<commit_msg>Add caching of source line fetching<commit_after><?php
/*
 * This file is part of the PHP_CodeCoverage package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Driver for Phpdbg's code coverage functionality.
 *
 * @since Class available since Release 2.2.0
 * @codeCoverageIgnore
 */
class PHP_CodeCoverage_Driver_Phpdbg implements PHP_CodeCoverage_Driver
{
    /**
     * Constructor.
     */
    public function __construct()
    {
        if (PHP_SAPI !== 'phpdbg') {
            throw new PHP_CodeCoverage_Exception('This driver requires the phpdbg sapi');
        }

        if (version_compare(phpversion(), '7.0', '<')) {
            // actually we require the phpdbg version shipped with php7, not php7 itself
            throw new PHP_CodeCoverage_Exception(
                'phpdbg based code coverage requires at least php7'
            );
        }
    }

    /**
     * Start collection of code coverage information.
     */
    public function start()
    {
       phpdbg_start_oplog();
    }

    /**
     * Stop collection of code coverage information.
     *
     * @return array
     */
    public function stop()
    {
        static $fetchedLines = array();

        $dbgData = phpdbg_end_oplog();

        if ($fetchedLines == array()) {
            $sourceLines = phpdbg_get_executable();
        } else {
            $newFiles = array_diff(get_included_files(), array_keys($fetchedLines));
            if ($newFiles) {
                $sourceLines = phpdbg_get_executable(array("files" => $newFiles));
            } else {
                $sourceLines = array();
            }
        }

        foreach ($sourceLines as &$lines) {
            foreach ($lines as &$line) {
                $line = self::LINE_NOT_EXECUTED;
            }
        }

        $fetchedLines += $sourceLines;

        $data = $this->detectExecutedLines($fetchedLines, $dbgData);

{'fraction_non_alphanumeric': 0.10467079347214406, 'fraction_numerical': 0.004501969611705121, 'mean_word_length': 2.146017699115044, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, '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': '5089318', 'n_tokens_mistral': 1036, 'n_tokens_neox': 974, 'n_words': 279}