<commit_before><?php

namespace coverallskit\example;

require_once __DIR__ . '/../vendor/autoload.php';

use coverallskit\JSONFileBuilder;
use coverallskit\entity\service\Travis;
use coverallskit\entity\Coverage;
use coverallskit\entity\Repository;
use coverallskit\entity\SourceFile;

/**
 * Get the code coverage
 */
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

$argv = array('../vendor/bin/pho');

require_once __DIR__ . "/../vendor/bin/pho";

$result = xdebug_get_code_coverage();
xdebug_stop_code_coverage();


/**
 * Generate a json file
 */
$builder = new JSONFileBuilder();
$builder->token('<KEY>')
    ->service(Travis::travisCI())
    ->repository(new Repository(__DIR__ . '/../'));

foreach ($result as $file => $coverage) {
    if (preg_match('/vendor/', $file) || preg_match('/spec/', $file)) {
        continue;
    }

    $source = new SourceFile($file);

    foreach ($coverage as $line => $status) {
        if ($status === 1) {
            $source->addCoverage(Coverage::executed($line));
        } else if ($status === -1) {
            $source->addCoverage(Coverage::unused($line));
        }
    }

    $builder->addSource($source);
}

$coverageFile = __DIR__ . '/coverage.json';

$builder->build()->saveAs($coverageFile)->upload();<commit_msg>add catch Exception<commit_after><?php

namespace coverallskit\example;

require_once __DIR__ . '/../vendor/autoload.php';

use coverallskit\JSONFileBuilder;
use coverallskit\entity\service\Travis;
use coverallskit\entity\Coverage;
use coverallskit\entity\Repository;
use coverallskit\entity\SourceFile;
use coverallskit\exception\LineOutOfRangeException;

/**
 * Get the code coverage
 */
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

$argv = array('../vendor/bin/pho');

require_once __DIR__ . "/../vendor/bin/pho";

$result = xdebug_get_code_coverage();
xdebug_stop_code_coverage();


/**
 * Generate a json file
 */
$builder = new JSONFileBuilder();
$builder->token('<KEY>')
    ->service(Travis::travisCI())
    ->repository(new Repository(__DIR__ . '/../'));

foreach ($result as $file => $coverage) {
    if (preg_match('/vendor/', $file) || preg_match('/spec/', $file)) {
        continue;
    }

    $source = new SourceFile($file);

    foreach ($coverage as $line => $status) {
        try {
            if ($status === 1) {
                $source->addCoverage(Coverage::executed($line));
            } else if ($status === -1) {
                $source->addCoverage(Coverage::unused($line));
            }
        } catch (LineOutOfRangeException $exception) {
            echo $source->getName() . PHP_EOL;
            echo $exception->getMessage() . PHP_EOL;
        }
    }

    $builder->addSource($source);
}

$coverageFile = __DIR__ . '/coverage.json';

$builder->build()->saveAs($coverageFile)->upload();
{'fraction_non_alphanumeric': 0.1706027493831512, 'fraction_numerical': 0.0014099400775467042, 'mean_word_length': 3.497622820919176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '2317469', 'n_tokens_mistral': 951, 'n_tokens_neox': 941, 'n_words': 161}