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

Breadcrumb

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

function VersionControl::generateFileReport

Generate a partial report for a single processed file.

Function should return TRUE if it printed or stored data about the file and FALSE if it ignored the file. Returning TRUE indicates that the file and its data should be counted in the grand totals.

Parameters

array<string, string|int|array> $report Prepared report data.: See the {@see Report} interface for a detailed specification.

\PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.:

bool $showSources Show sources?:

int $width Maximum allowed line width.:

Return value

bool

Overrides Report::generateFileReport

File

vendor/squizlabs/php_codesniffer/src/Reports/VersionControl.php, line 42

Class

VersionControl

Namespace

PHP_CodeSniffer\Reports

Code

public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80) {
    $blames = $this->getBlameContent($phpcsFile->getFilename());
    $authorCache = [];
    $praiseCache = [];
    $sourceCache = [];
    foreach ($report['messages'] as $line => $lineErrors) {
        $author = 'Unknown';
        if (isset($blames[$line - 1]) === true) {
            $blameAuthor = $this->getAuthor($blames[$line - 1]);
            if ($blameAuthor !== false) {
                $author = $blameAuthor;
            }
        }
        if (isset($authorCache[$author]) === false) {
            $authorCache[$author] = 0;
            $praiseCache[$author] = [
                'good' => 0,
                'bad' => 0,
            ];
        }
        $praiseCache[$author]['bad']++;
        foreach ($lineErrors as $colErrors) {
            foreach ($colErrors as $error) {
                $authorCache[$author]++;
                if ($showSources === true) {
                    $source = $error['source'];
                    if (isset($sourceCache[$author][$source]) === false) {
                        $sourceCache[$author][$source] = [
                            'count' => 1,
                            'fixable' => $error['fixable'],
                        ];
                    }
                    else {
                        $sourceCache[$author][$source]['count']++;
                    }
                }
            }
        }
        unset($blames[$line - 1]);
    }
    
    //end foreach
    // Now go through and give the authors some credit for
    // all the lines that do not have errors.
    foreach ($blames as $line) {
        $author = $this->getAuthor($line);
        if ($author === false) {
            $author = 'Unknown';
        }
        if (isset($authorCache[$author]) === false) {
            // This author doesn't have any errors.
            if (PHP_CODESNIFFER_VERBOSITY === 0) {
                continue;
            }
            $authorCache[$author] = 0;
            $praiseCache[$author] = [
                'good' => 0,
                'bad' => 0,
            ];
        }
        $praiseCache[$author]['good']++;
    }
    
    //end foreach
    foreach ($authorCache as $author => $errors) {
        echo "AUTHOR>>{$author}>>{$errors}" . PHP_EOL;
    }
    foreach ($praiseCache as $author => $praise) {
        echo "PRAISE>>{$author}>>" . $praise['good'] . '>>' . $praise['bad'] . PHP_EOL;
    }
    foreach ($sourceCache as $author => $sources) {
        foreach ($sources as $source => $sourceData) {
            $count = $sourceData['count'];
            $fixable = (int) $sourceData['fixable'];
            echo "SOURCE>>{$author}>>{$source}>>{$count}>>{$fixable}" . PHP_EOL;
        }
    }
    return true;
}

API Navigation

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