403Webshell
Server IP : 35.80.110.71  /  Your IP : 216.73.216.221
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/2798582/cwd/scripts/ci/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/2798582/cwd/scripts/ci/check-coverage.php
<?php

declare(strict_types=1);

/**
 * Parses a PHPUnit Clover XML coverage report and enforces a minimum
 * line-coverage threshold. Exit code:
 *  - 0 if coverage >= threshold
 *  - 1 if coverage < threshold or the file cannot be read
 *
 * Usage: php scripts/ci/check-coverage.php tests/.coverage/clover.xml [threshold]
 *
 * The threshold defaults to CI_COVERAGE_MIN env var, falling back to 60.
 * The floor is intentionally permissive so it does not block initial
 * adoption; raise via the env var in the workflow as the suite improves.
 */
$cloverPath = $argv[1] ?? 'tests/.coverage/clover.xml';
$threshold = isset($argv[2])
    ? (float) $argv[2]
    : (float) (getenv('CI_COVERAGE_MIN') ?: 60);

if (! is_file($cloverPath) || ! is_readable($cloverPath)) {
    fwrite(STDERR, "Coverage file not found: {$cloverPath}\n");
    exit(1);
}

$xml = @simplexml_load_file($cloverPath);
if ($xml === false) {
    fwrite(STDERR, "Failed to parse coverage file: {$cloverPath}\n");
    exit(1);
}

$metrics = $xml->project->metrics ?? null;
if ($metrics === null) {
    fwrite(STDERR, "No <project><metrics> node found in coverage report.\n");
    exit(1);
}

$statements = (int) $metrics['statements'];
$covered = (int) $metrics['coveredstatements'];

if ($statements === 0) {
    fwrite(STDERR, "Coverage report reports 0 statements — refusing to pass.\n");
    exit(1);
}

$percent = ($covered / $statements) * 100;
$percentFormatted = number_format($percent, 2);
$thresholdFormatted = number_format($threshold, 2);

echo "Line coverage: {$percentFormatted}% ({$covered}/{$statements})\n";
echo "Threshold:     {$thresholdFormatted}%\n";

if ($percent + 0.001 < $threshold) {
    fwrite(STDERR, "::error::Coverage {$percentFormatted}% is below threshold {$thresholdFormatted}%\n");
    exit(1);
}

echo "Coverage check passed.\n";
exit(0);

Youez - 2016 - github.com/yon3zu
LinuXploit