Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Summary.php

function Summary::generate

Generates a summary of errors and warnings for each file processed.

Parameters

string $cachedData Any partial report data that was returned from: generateFileReport during the run.

int $totalFiles Total number of files processed during the run.:

int $totalErrors Total number of errors found during the run.:

int $totalWarnings Total number of warnings found during the run.:

int $totalFixable Total number of problems that can be fixed.:

bool $showSources Show sources?:

int $width Maximum allowed line width.:

bool $interactive Are we running in interactive mode?:

bool $toScreen Is the report being printed to screen?:

Return value

void

Overrides Report::generate

File

vendor/squizlabs/php_codesniffer/src/Reports/Summary.php, line 66

Class

Summary

Namespace

PHP_CodeSniffer\Reports

Code

public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $interactive = false, $toScreen = true) {
    $lines = explode(PHP_EOL, $cachedData);
    array_pop($lines);
    if (empty($lines) === true) {
        return;
    }
    $reportFiles = [];
    $maxLength = 0;
    foreach ($lines as $line) {
        $parts = explode('>>', $line);
        $fileLen = strlen($parts[0]);
        $reportFiles[$parts[0]] = [
            'errors' => $parts[1],
            'warnings' => $parts[2],
            'strlen' => $fileLen,
        ];
        $maxLength = max($maxLength, $fileLen);
    }
    uksort($reportFiles, function ($keyA, $keyB) {
        $pathPartsA = explode(DIRECTORY_SEPARATOR, $keyA);
        $pathPartsB = explode(DIRECTORY_SEPARATOR, $keyB);
        do {
            $partA = array_shift($pathPartsA);
            $partB = array_shift($pathPartsB);
        } while ($partA === $partB && empty($pathPartsA) === false && empty($pathPartsB) === false);
        if (empty($pathPartsA) === false && empty($pathPartsB) === true) {
            return 1;
        }
        else {
            if (empty($pathPartsA) === true && empty($pathPartsB) === false) {
                return -1;
            }
            else {
                return strcasecmp($partA, $partB);
            }
        }
    });
    $width = min($width, $maxLength + 21);
    $width = max($width, 70);
    echo PHP_EOL . "\x1b[1m" . 'PHP CODE SNIFFER REPORT SUMMARY' . "\x1b[0m" . PHP_EOL;
    echo str_repeat('-', $width) . PHP_EOL;
    echo "\x1b[1m" . 'FILE' . str_repeat(' ', $width - 20) . 'ERRORS  WARNINGS' . "\x1b[0m" . PHP_EOL;
    echo str_repeat('-', $width) . PHP_EOL;
    foreach ($reportFiles as $file => $data) {
        $padding = $width - 18 - $data['strlen'];
        if ($padding < 0) {
            $file = '...' . substr($file, $padding * -1 + 3);
            $padding = 0;
        }
        echo $file . str_repeat(' ', $padding) . '  ';
        if ($data['errors'] !== 0) {
            echo "\x1b[31m" . $data['errors'] . "\x1b[0m";
            echo str_repeat(' ', 8 - strlen((string) $data['errors']));
        }
        else {
            echo '0       ';
        }
        if ($data['warnings'] !== 0) {
            echo "\x1b[33m" . $data['warnings'] . "\x1b[0m";
        }
        else {
            echo '0';
        }
        echo PHP_EOL;
    }
    
    //end foreach
    echo str_repeat('-', $width) . PHP_EOL;
    echo "\x1b[1mA TOTAL OF {$totalErrors} ERROR";
    if ($totalErrors !== 1) {
        echo 'S';
    }
    echo ' AND ' . $totalWarnings . ' WARNING';
    if ($totalWarnings !== 1) {
        echo 'S';
    }
    echo ' WERE FOUND IN ' . $totalFiles . ' FILE';
    if ($totalFiles !== 1) {
        echo 'S';
    }
    echo "\x1b[0m";
    if ($totalFixable > 0) {
        echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
        echo "\x1b[1mPHPCBF CAN FIX {$totalFixable} OF THESE SNIFF VIOLATIONS AUTOMATICALLY\x1b[0m";
    }
    echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
    if ($toScreen === true && $interactive === false) {
        Timing::printRunTime();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal