more updates yay
This commit is contained in:
249
vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php
vendored
Normal file
249
vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php
vendored
Normal file
@ -0,0 +1,249 @@
|
||||
<?php
|
||||
/**
|
||||
* CBF report for PHP_CodeSniffer.
|
||||
*
|
||||
* This report implements the various auto-fixing features of the
|
||||
* PHPCBF script and is not intended (or allowed) to be selected as a
|
||||
* report from the command line.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Exceptions\DeepExitException;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util;
|
||||
|
||||
class Cbf implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$errors = $phpcsFile->getFixableCount();
|
||||
if ($errors !== 0) {
|
||||
if (PHP_CODESNIFFER_VERBOSITY > 0) {
|
||||
ob_end_clean();
|
||||
$startTime = microtime(true);
|
||||
echo "\t=> Fixing file: $errors/$errors violations remaining";
|
||||
}
|
||||
|
||||
$fixed = $phpcsFile->fixer->fixFile();
|
||||
}
|
||||
|
||||
if ($phpcsFile->config->stdin === true) {
|
||||
// Replacing STDIN, so output current file to STDOUT
|
||||
// even if nothing was fixed. Exit here because we
|
||||
// can't process any more than 1 file in this setup.
|
||||
$fixedContent = $phpcsFile->fixer->getContents();
|
||||
throw new DeepExitException($fixedContent, 1);
|
||||
}
|
||||
|
||||
if ($errors === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY > 0) {
|
||||
if ($fixed === false) {
|
||||
echo 'ERROR';
|
||||
} else {
|
||||
echo 'DONE';
|
||||
}
|
||||
|
||||
$timeTaken = ((microtime(true) - $startTime) * 1000);
|
||||
if ($timeTaken < 1000) {
|
||||
$timeTaken = round($timeTaken);
|
||||
echo " in {$timeTaken}ms".PHP_EOL;
|
||||
} else {
|
||||
$timeTaken = round(($timeTaken / 1000), 2);
|
||||
echo " in $timeTaken secs".PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($fixed === true) {
|
||||
// The filename in the report may be truncated due to a basepath setting
|
||||
// but we are using it for writing here and not display,
|
||||
// so find the correct path if basepath is in use.
|
||||
$newFilename = $report['filename'].$phpcsFile->config->suffix;
|
||||
if ($phpcsFile->config->basepath !== null) {
|
||||
$newFilename = $phpcsFile->config->basepath.DIRECTORY_SEPARATOR.$newFilename;
|
||||
}
|
||||
|
||||
$newContent = $phpcsFile->fixer->getContents();
|
||||
file_put_contents($newFilename, $newContent);
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY > 0) {
|
||||
if ($newFilename === $report['filename']) {
|
||||
echo "\t=> File was overwritten".PHP_EOL;
|
||||
} else {
|
||||
echo "\t=> Fixed file written to ".basename($newFilename).PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY > 0) {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
$errorCount = $phpcsFile->getErrorCount();
|
||||
$warningCount = $phpcsFile->getWarningCount();
|
||||
$fixableCount = $phpcsFile->getFixableCount();
|
||||
$fixedCount = ($errors - $fixableCount);
|
||||
echo $report['filename'].">>$errorCount>>$warningCount>>$fixableCount>>$fixedCount".PHP_EOL;
|
||||
|
||||
return $fixed;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints a summary of fixed files.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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) {
|
||||
echo PHP_EOL.'No fixable errors were found'.PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
$reportFiles = [];
|
||||
$maxLength = 0;
|
||||
$totalFixed = 0;
|
||||
$failures = 0;
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode('>>', $line);
|
||||
$fileLen = strlen($parts[0]);
|
||||
$reportFiles[$parts[0]] = [
|
||||
'errors' => $parts[1],
|
||||
'warnings' => $parts[2],
|
||||
'fixable' => $parts[3],
|
||||
'fixed' => $parts[4],
|
||||
'strlen' => $fileLen,
|
||||
];
|
||||
|
||||
$maxLength = max($maxLength, $fileLen);
|
||||
|
||||
$totalFixed += $parts[4];
|
||||
|
||||
if ($parts[3] > 0) {
|
||||
$failures++;
|
||||
}
|
||||
}
|
||||
|
||||
$width = min($width, ($maxLength + 21));
|
||||
$width = max($width, 70);
|
||||
|
||||
echo PHP_EOL."\033[1m".'PHPCBF RESULT SUMMARY'."\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'FIXED REMAINING'."\033[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['fixable'] > 0) {
|
||||
echo "\033[31mFAILED TO FIX\033[0m".PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
$remaining = ($data['errors'] + $data['warnings']);
|
||||
|
||||
if ($data['fixed'] !== 0) {
|
||||
echo $data['fixed'];
|
||||
echo str_repeat(' ', (7 - strlen((string) $data['fixed'])));
|
||||
} else {
|
||||
echo '0 ';
|
||||
}
|
||||
|
||||
if ($remaining !== 0) {
|
||||
echo $remaining;
|
||||
} else {
|
||||
echo '0';
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1mA TOTAL OF $totalFixed ERROR";
|
||||
if ($totalFixed !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
$numFiles = count($reportFiles);
|
||||
echo ' WERE FIXED IN '.$numFiles.' FILE';
|
||||
if ($numFiles !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo "\033[0m";
|
||||
|
||||
if ($failures > 0) {
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1mPHPCBF FAILED TO FIX $failures FILE";
|
||||
if ($failures !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo "\033[0m";
|
||||
}
|
||||
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Util\Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
109
vendor/squizlabs/php_codesniffer/src/Reports/Checkstyle.php
vendored
Normal file
109
vendor/squizlabs/php_codesniffer/src/Reports/Checkstyle.php
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Checkstyle report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Config;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Checkstyle implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$out = new \XMLWriter;
|
||||
$out->openMemory();
|
||||
$out->setIndent(true);
|
||||
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
$out->startElement('file');
|
||||
$out->writeAttribute('name', $report['filename']);
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$error['type'] = strtolower($error['type']);
|
||||
if ($phpcsFile->config->encoding !== 'utf-8') {
|
||||
$error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
|
||||
}
|
||||
|
||||
$out->startElement('error');
|
||||
$out->writeAttribute('line', $line);
|
||||
$out->writeAttribute('column', $column);
|
||||
$out->writeAttribute('severity', $error['type']);
|
||||
$out->writeAttribute('message', $error['message']);
|
||||
$out->writeAttribute('source', $error['source']);
|
||||
$out->endElement();
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$out->endElement();
|
||||
echo $out->flush();
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints all violations for processed files, in a Checkstyle format.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
|
||||
echo '<checkstyle version="'.Config::VERSION.'">'.PHP_EOL;
|
||||
echo $cachedData;
|
||||
echo '</checkstyle>'.PHP_EOL;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
362
vendor/squizlabs/php_codesniffer/src/Reports/Code.php
vendored
Normal file
362
vendor/squizlabs/php_codesniffer/src/Reports/Code.php
vendored
Normal file
@ -0,0 +1,362 @@
|
||||
<?php
|
||||
/**
|
||||
* Full report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util;
|
||||
|
||||
class Code implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
// How many lines to show about and below the error line.
|
||||
$surroundingLines = 2;
|
||||
|
||||
$file = $report['filename'];
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
if (empty($tokens) === true) {
|
||||
if (PHP_CODESNIFFER_VERBOSITY === 1) {
|
||||
$startTime = microtime(true);
|
||||
echo 'CODE report is parsing '.basename($file).' ';
|
||||
} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
||||
echo "CODE report is forcing parse of $file".PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
$phpcsFile->parse();
|
||||
} catch (\Exception $e) {
|
||||
// This is a second parse, so ignore exceptions.
|
||||
// They would have been added to the file's error list already.
|
||||
}
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY === 1) {
|
||||
$timeTaken = ((microtime(true) - $startTime) * 1000);
|
||||
if ($timeTaken < 1000) {
|
||||
$timeTaken = round($timeTaken);
|
||||
echo "DONE in {$timeTaken}ms";
|
||||
} else {
|
||||
$timeTaken = round(($timeTaken / 1000), 2);
|
||||
echo "DONE in $timeTaken secs";
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
}//end if
|
||||
|
||||
// Create an array that maps lines to the first token on the line.
|
||||
$lineTokens = [];
|
||||
$lastLine = 0;
|
||||
$stackPtr = 0;
|
||||
foreach ($tokens as $stackPtr => $token) {
|
||||
if ($token['line'] !== $lastLine) {
|
||||
if ($lastLine > 0) {
|
||||
$lineTokens[$lastLine]['end'] = ($stackPtr - 1);
|
||||
}
|
||||
|
||||
$lastLine++;
|
||||
$lineTokens[$lastLine] = [
|
||||
'start' => $stackPtr,
|
||||
'end' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the last token in the file sits on an imaginary
|
||||
// last line so it is easier to generate code snippets at the
|
||||
// end of the file.
|
||||
$lineTokens[$lastLine]['end'] = $stackPtr;
|
||||
|
||||
// Determine the longest code line we will be showing.
|
||||
$maxSnippetLength = 0;
|
||||
$eolLen = strlen($phpcsFile->eolChar);
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
$startLine = max(($line - $surroundingLines), 1);
|
||||
$endLine = min(($line + $surroundingLines), $lastLine);
|
||||
|
||||
$maxLineNumLength = strlen($endLine);
|
||||
|
||||
for ($i = $startLine; $i <= $endLine; $i++) {
|
||||
if ($i === 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lineLength = ($tokens[($lineTokens[$i]['start'] - 1)]['column'] + $tokens[($lineTokens[$i]['start'] - 1)]['length'] - $eolLen);
|
||||
$maxSnippetLength = max($lineLength, $maxSnippetLength);
|
||||
}
|
||||
}
|
||||
|
||||
$maxSnippetLength += ($maxLineNumLength + 8);
|
||||
|
||||
// Determine the longest error message we will be showing.
|
||||
$maxErrorLength = 0;
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$length = strlen($error['message']);
|
||||
if ($showSources === true) {
|
||||
$length += (strlen($error['source']) + 3);
|
||||
}
|
||||
|
||||
$maxErrorLength = max($maxErrorLength, ($length + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The padding that all lines will require that are printing an error message overflow.
|
||||
if ($report['warnings'] > 0) {
|
||||
$typeLength = 7;
|
||||
} else {
|
||||
$typeLength = 5;
|
||||
}
|
||||
|
||||
$errorPadding = str_repeat(' ', ($maxLineNumLength + 7));
|
||||
$errorPadding .= str_repeat(' ', $typeLength);
|
||||
$errorPadding .= ' ';
|
||||
if ($report['fixable'] > 0) {
|
||||
$errorPadding .= ' ';
|
||||
}
|
||||
|
||||
$errorPaddingLength = strlen($errorPadding);
|
||||
|
||||
// The maximum amount of space an error message can use.
|
||||
$maxErrorSpace = ($width - $errorPaddingLength);
|
||||
if ($showSources === true) {
|
||||
// Account for the chars used to print colors.
|
||||
$maxErrorSpace += 8;
|
||||
}
|
||||
|
||||
// Figure out the max report width we need and can use.
|
||||
$fileLength = strlen($file);
|
||||
$maxWidth = max(($fileLength + 6), ($maxErrorLength + $errorPaddingLength));
|
||||
$width = max(min($width, $maxWidth), $maxSnippetLength);
|
||||
if ($width < 70) {
|
||||
$width = 70;
|
||||
}
|
||||
|
||||
// Print the file header.
|
||||
echo PHP_EOL."\033[1mFILE: ";
|
||||
if ($fileLength <= ($width - 6)) {
|
||||
echo $file;
|
||||
} else {
|
||||
echo '...'.substr($file, ($fileLength - ($width - 6)));
|
||||
}
|
||||
|
||||
echo "\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
|
||||
echo "\033[1m".'FOUND '.$report['errors'].' ERROR';
|
||||
if ($report['errors'] !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
if ($report['warnings'] > 0) {
|
||||
echo ' AND '.$report['warnings'].' WARNING';
|
||||
if ($report['warnings'] !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
}
|
||||
|
||||
echo ' AFFECTING '.count($report['messages']).' LINE';
|
||||
if (count($report['messages']) !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo "\033[0m".PHP_EOL;
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
$startLine = max(($line - $surroundingLines), 1);
|
||||
$endLine = min(($line + $surroundingLines), $lastLine);
|
||||
|
||||
$snippet = '';
|
||||
if (isset($lineTokens[$startLine]) === true) {
|
||||
for ($i = $lineTokens[$startLine]['start']; $i <= $lineTokens[$endLine]['end']; $i++) {
|
||||
$snippetLine = $tokens[$i]['line'];
|
||||
if ($lineTokens[$snippetLine]['start'] === $i) {
|
||||
// Starting a new line.
|
||||
if ($snippetLine === $line) {
|
||||
$snippet .= "\033[1m".'>> ';
|
||||
} else {
|
||||
$snippet .= ' ';
|
||||
}
|
||||
|
||||
$snippet .= str_repeat(' ', ($maxLineNumLength - strlen($snippetLine)));
|
||||
$snippet .= $snippetLine.': ';
|
||||
if ($snippetLine === $line) {
|
||||
$snippet .= "\033[0m";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($tokens[$i]['orig_content']) === true) {
|
||||
$tokenContent = $tokens[$i]['orig_content'];
|
||||
} else {
|
||||
$tokenContent = $tokens[$i]['content'];
|
||||
}
|
||||
|
||||
if (strpos($tokenContent, "\t") !== false) {
|
||||
$token = $tokens[$i];
|
||||
$token['content'] = $tokenContent;
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$tab = "\000";
|
||||
} else {
|
||||
$tab = "\033[30;1m»\033[0m";
|
||||
}
|
||||
|
||||
$phpcsFile->tokenizer->replaceTabsInToken($token, $tab, "\000");
|
||||
$tokenContent = $token['content'];
|
||||
}
|
||||
|
||||
$tokenContent = Util\Common::prepareForOutput($tokenContent, ["\r", "\n", "\t"]);
|
||||
$tokenContent = str_replace("\000", ' ', $tokenContent);
|
||||
|
||||
$underline = false;
|
||||
if ($snippetLine === $line && isset($lineErrors[$tokens[$i]['column']]) === true) {
|
||||
$underline = true;
|
||||
}
|
||||
|
||||
// Underline invisible characters as well.
|
||||
if ($underline === true && trim($tokenContent) === '') {
|
||||
$snippet .= "\033[4m".' '."\033[0m".$tokenContent;
|
||||
} else {
|
||||
if ($underline === true) {
|
||||
$snippet .= "\033[4m";
|
||||
}
|
||||
|
||||
$snippet .= $tokenContent;
|
||||
|
||||
if ($underline === true) {
|
||||
$snippet .= "\033[0m";
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
}//end if
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$padding = ($maxLineNumLength - strlen($line));
|
||||
echo 'LINE '.str_repeat(' ', $padding).$line.': ';
|
||||
|
||||
if ($error['type'] === 'ERROR') {
|
||||
echo "\033[31mERROR\033[0m";
|
||||
if ($report['warnings'] > 0) {
|
||||
echo ' ';
|
||||
}
|
||||
} else {
|
||||
echo "\033[33mWARNING\033[0m";
|
||||
}
|
||||
|
||||
echo ' ';
|
||||
if ($report['fixable'] > 0) {
|
||||
echo '[';
|
||||
if ($error['fixable'] === true) {
|
||||
echo 'x';
|
||||
} else {
|
||||
echo ' ';
|
||||
}
|
||||
|
||||
echo '] ';
|
||||
}
|
||||
|
||||
$message = $error['message'];
|
||||
$message = str_replace("\n", "\n".$errorPadding, $message);
|
||||
if ($showSources === true) {
|
||||
$message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
|
||||
}
|
||||
|
||||
$errorMsg = wordwrap(
|
||||
$message,
|
||||
$maxErrorSpace,
|
||||
PHP_EOL.$errorPadding
|
||||
);
|
||||
|
||||
echo $errorMsg.PHP_EOL;
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo rtrim($snippet).PHP_EOL;
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
if ($report['fixable'] > 0) {
|
||||
echo "\033[1m".'PHPCBF CAN FIX THE '.$report['fixable'].' MARKED SNIFF VIOLATIONS AUTOMATICALLY'."\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints all errors and warnings for each file processed.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
if ($cachedData === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
echo $cachedData;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Util\Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
91
vendor/squizlabs/php_codesniffer/src/Reports/Csv.php
vendored
Normal file
91
vendor/squizlabs/php_codesniffer/src/Reports/Csv.php
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* CSV report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Csv implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$filename = str_replace('"', '\"', $report['filename']);
|
||||
$message = str_replace('"', '\"', $error['message']);
|
||||
$type = strtolower($error['type']);
|
||||
$source = $error['source'];
|
||||
$severity = $error['severity'];
|
||||
$fixable = (int) $error['fixable'];
|
||||
echo "\"$filename\",$line,$column,$type,\"$message\",$source,$severity,$fixable".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Generates a csv report.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
echo 'File,Line,Column,Type,Message,Source,Severity,Fixable'.PHP_EOL;
|
||||
echo $cachedData;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
131
vendor/squizlabs/php_codesniffer/src/Reports/Diff.php
vendored
Normal file
131
vendor/squizlabs/php_codesniffer/src/Reports/Diff.php
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Diff report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util;
|
||||
|
||||
class Diff implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$errors = $phpcsFile->getFixableCount();
|
||||
if ($errors === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$phpcsFile->disableCaching();
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
if (empty($tokens) === true) {
|
||||
if (PHP_CODESNIFFER_VERBOSITY === 1) {
|
||||
$startTime = microtime(true);
|
||||
echo 'DIFF report is parsing '.basename($report['filename']).' ';
|
||||
} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
||||
echo 'DIFF report is forcing parse of '.$report['filename'].PHP_EOL;
|
||||
}
|
||||
|
||||
$phpcsFile->parse();
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY === 1) {
|
||||
$timeTaken = ((microtime(true) - $startTime) * 1000);
|
||||
if ($timeTaken < 1000) {
|
||||
$timeTaken = round($timeTaken);
|
||||
echo "DONE in {$timeTaken}ms";
|
||||
} else {
|
||||
$timeTaken = round(($timeTaken / 1000), 2);
|
||||
echo "DONE in $timeTaken secs";
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}
|
||||
|
||||
$phpcsFile->fixer->startFile($phpcsFile);
|
||||
}//end if
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
||||
ob_end_clean();
|
||||
echo "\t*** START FILE FIXING ***".PHP_EOL;
|
||||
}
|
||||
|
||||
$fixed = $phpcsFile->fixer->fixFile();
|
||||
|
||||
if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
||||
echo "\t*** END FILE FIXING ***".PHP_EOL;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
if ($fixed === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$diff = $phpcsFile->fixer->generateDiff();
|
||||
if ($diff === '') {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
echo $diff.PHP_EOL;
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints all errors and warnings for each file processed.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
echo $cachedData;
|
||||
if ($toScreen === true && $cachedData !== '') {
|
||||
echo PHP_EOL;
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
90
vendor/squizlabs/php_codesniffer/src/Reports/Emacs.php
vendored
Normal file
90
vendor/squizlabs/php_codesniffer/src/Reports/Emacs.php
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Emacs report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Emacs implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$message = $error['message'];
|
||||
if ($showSources === true) {
|
||||
$message .= ' ('.$error['source'].')';
|
||||
}
|
||||
|
||||
$type = strtolower($error['type']);
|
||||
echo $report['filename'].':'.$line.':'.$column.': '.$type.' - '.$message.PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Generates an emacs report.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
echo $cachedData;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
218
vendor/squizlabs/php_codesniffer/src/Reports/Full.php
vendored
Normal file
218
vendor/squizlabs/php_codesniffer/src/Reports/Full.php
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* Full report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util;
|
||||
|
||||
class Full implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
// The length of the word ERROR or WARNING; used for padding.
|
||||
if ($report['warnings'] > 0) {
|
||||
$typeLength = 7;
|
||||
} else {
|
||||
$typeLength = 5;
|
||||
}
|
||||
|
||||
// Work out the max line number length for formatting.
|
||||
$maxLineNumLength = max(array_map('strlen', array_keys($report['messages'])));
|
||||
|
||||
// The padding that all lines will require that are
|
||||
// printing an error message overflow.
|
||||
$paddingLine2 = str_repeat(' ', ($maxLineNumLength + 1));
|
||||
$paddingLine2 .= ' | ';
|
||||
$paddingLine2 .= str_repeat(' ', $typeLength);
|
||||
$paddingLine2 .= ' | ';
|
||||
if ($report['fixable'] > 0) {
|
||||
$paddingLine2 .= ' ';
|
||||
}
|
||||
|
||||
$paddingLength = strlen($paddingLine2);
|
||||
|
||||
// Make sure the report width isn't too big.
|
||||
$maxErrorLength = 0;
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$length = strlen($error['message']);
|
||||
if ($showSources === true) {
|
||||
$length += (strlen($error['source']) + 3);
|
||||
}
|
||||
|
||||
$maxErrorLength = max($maxErrorLength, ($length + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file = $report['filename'];
|
||||
$fileLength = strlen($file);
|
||||
$maxWidth = max(($fileLength + 6), ($maxErrorLength + $paddingLength));
|
||||
$width = min($width, $maxWidth);
|
||||
if ($width < 70) {
|
||||
$width = 70;
|
||||
}
|
||||
|
||||
echo PHP_EOL."\033[1mFILE: ";
|
||||
if ($fileLength <= ($width - 6)) {
|
||||
echo $file;
|
||||
} else {
|
||||
echo '...'.substr($file, ($fileLength - ($width - 6)));
|
||||
}
|
||||
|
||||
echo "\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
|
||||
echo "\033[1m".'FOUND '.$report['errors'].' ERROR';
|
||||
if ($report['errors'] !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
if ($report['warnings'] > 0) {
|
||||
echo ' AND '.$report['warnings'].' WARNING';
|
||||
if ($report['warnings'] !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
}
|
||||
|
||||
echo ' AFFECTING '.count($report['messages']).' LINE';
|
||||
if (count($report['messages']) !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo "\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
|
||||
// The maximum amount of space an error message can use.
|
||||
$maxErrorSpace = ($width - $paddingLength - 1);
|
||||
if ($showSources === true) {
|
||||
// Account for the chars used to print colors.
|
||||
$maxErrorSpace += 8;
|
||||
}
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$message = $error['message'];
|
||||
$message = str_replace("\n", "\n".$paddingLine2, $message);
|
||||
if ($showSources === true) {
|
||||
$message = "\033[1m".$message."\033[0m".' ('.$error['source'].')';
|
||||
}
|
||||
|
||||
// The padding that goes on the front of the line.
|
||||
$padding = ($maxLineNumLength - strlen($line));
|
||||
$errorMsg = wordwrap(
|
||||
$message,
|
||||
$maxErrorSpace,
|
||||
PHP_EOL.$paddingLine2
|
||||
);
|
||||
|
||||
echo ' '.str_repeat(' ', $padding).$line.' | ';
|
||||
if ($error['type'] === 'ERROR') {
|
||||
echo "\033[31mERROR\033[0m";
|
||||
if ($report['warnings'] > 0) {
|
||||
echo ' ';
|
||||
}
|
||||
} else {
|
||||
echo "\033[33mWARNING\033[0m";
|
||||
}
|
||||
|
||||
echo ' | ';
|
||||
if ($report['fixable'] > 0) {
|
||||
echo '[';
|
||||
if ($error['fixable'] === true) {
|
||||
echo 'x';
|
||||
} else {
|
||||
echo ' ';
|
||||
}
|
||||
|
||||
echo '] ';
|
||||
}
|
||||
|
||||
echo $errorMsg.PHP_EOL;
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
if ($report['fixable'] > 0) {
|
||||
echo "\033[1m".'PHPCBF CAN FIX THE '.$report['fixable'].' MARKED SNIFF VIOLATIONS AUTOMATICALLY'."\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints all errors and warnings for each file processed.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
if ($cachedData === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
echo $cachedData;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Util\Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
90
vendor/squizlabs/php_codesniffer/src/Reports/Gitblame.php
vendored
Normal file
90
vendor/squizlabs/php_codesniffer/src/Reports/Gitblame.php
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Git blame report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Ben Selby <benmatselby@gmail.com>
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Exceptions\DeepExitException;
|
||||
|
||||
class Gitblame extends VersionControl
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the report we want in the output
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reportName = 'GIT';
|
||||
|
||||
|
||||
/**
|
||||
* Extract the author from a blame line.
|
||||
*
|
||||
* @param string $line Line to parse.
|
||||
*
|
||||
* @return mixed string or false if impossible to recover.
|
||||
*/
|
||||
protected function getAuthor($line)
|
||||
{
|
||||
$blameParts = [];
|
||||
$line = preg_replace('|\s+|', ' ', $line);
|
||||
preg_match(
|
||||
'|\(.+[0-9]{4}-[0-9]{2}-[0-9]{2}\s+[0-9]+\)|',
|
||||
$line,
|
||||
$blameParts
|
||||
);
|
||||
|
||||
if (isset($blameParts[0]) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode(' ', $blameParts[0]);
|
||||
|
||||
if (count($parts) < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = array_slice($parts, 0, (count($parts) - 2));
|
||||
$author = preg_replace('|\(|', '', implode($parts, ' '));
|
||||
return $author;
|
||||
|
||||
}//end getAuthor()
|
||||
|
||||
|
||||
/**
|
||||
* Gets the blame output.
|
||||
*
|
||||
* @param string $filename File to blame.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBlameContent($filename)
|
||||
{
|
||||
$cwd = getcwd();
|
||||
|
||||
chdir(dirname($filename));
|
||||
$command = 'git blame --date=short "'.$filename.'" 2>&1';
|
||||
$handle = popen($command, 'r');
|
||||
if ($handle === false) {
|
||||
$error = 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
|
||||
throw new DeepExitException($error, 3);
|
||||
}
|
||||
|
||||
$rawContent = stream_get_contents($handle);
|
||||
fclose($handle);
|
||||
|
||||
$blames = explode("\n", $rawContent);
|
||||
chdir($cwd);
|
||||
|
||||
return $blames;
|
||||
|
||||
}//end getBlameContent()
|
||||
|
||||
|
||||
}//end class
|
109
vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php
vendored
Normal file
109
vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Mercurial blame report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Ben Selby <benmatselby@gmail.com>
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Exceptions\DeepExitException;
|
||||
|
||||
class Hgblame extends VersionControl
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the report we want in the output
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reportName = 'MERCURIAL';
|
||||
|
||||
|
||||
/**
|
||||
* Extract the author from a blame line.
|
||||
*
|
||||
* @param string $line Line to parse.
|
||||
*
|
||||
* @return mixed string or false if impossible to recover.
|
||||
*/
|
||||
protected function getAuthor($line)
|
||||
{
|
||||
$blameParts = [];
|
||||
$line = preg_replace('|\s+|', ' ', $line);
|
||||
|
||||
preg_match(
|
||||
'|(.+[0-9]{2}:[0-9]{2}:[0-9]{2}\s[0-9]{4}\s.[0-9]{4}:)|',
|
||||
$line,
|
||||
$blameParts
|
||||
);
|
||||
|
||||
if (isset($blameParts[0]) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode(' ', $blameParts[0]);
|
||||
|
||||
if (count($parts) < 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = array_slice($parts, 0, (count($parts) - 6));
|
||||
|
||||
return trim(preg_replace('|<.+>|', '', implode($parts, ' ')));
|
||||
|
||||
}//end getAuthor()
|
||||
|
||||
|
||||
/**
|
||||
* Gets the blame output.
|
||||
*
|
||||
* @param string $filename File to blame.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBlameContent($filename)
|
||||
{
|
||||
$cwd = getcwd();
|
||||
|
||||
$fileParts = explode(DIRECTORY_SEPARATOR, $filename);
|
||||
$found = false;
|
||||
$location = '';
|
||||
while (empty($fileParts) === false) {
|
||||
array_pop($fileParts);
|
||||
$location = implode($fileParts, DIRECTORY_SEPARATOR);
|
||||
if (is_dir($location.DIRECTORY_SEPARATOR.'.hg') === true) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found === true) {
|
||||
chdir($location);
|
||||
} else {
|
||||
$error = 'ERROR: Could not locate .hg directory '.PHP_EOL.PHP_EOL;
|
||||
throw new DeepExitException($error, 3);
|
||||
}
|
||||
|
||||
$command = 'hg blame -u -d -v "'.$filename.'" 2>&1';
|
||||
$handle = popen($command, 'r');
|
||||
if ($handle === false) {
|
||||
$error = 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
|
||||
throw new DeepExitException($error, 3);
|
||||
}
|
||||
|
||||
$rawContent = stream_get_contents($handle);
|
||||
fclose($handle);
|
||||
|
||||
$blames = explode("\n", $rawContent);
|
||||
chdir($cwd);
|
||||
|
||||
return $blames;
|
||||
|
||||
}//end getBlameContent()
|
||||
|
||||
|
||||
}//end class
|
141
vendor/squizlabs/php_codesniffer/src/Reports/Info.php
vendored
Normal file
141
vendor/squizlabs/php_codesniffer/src/Reports/Info.php
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Info report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util\Timing;
|
||||
|
||||
class Info implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$metrics = $phpcsFile->getMetrics();
|
||||
foreach ($metrics as $metric => $data) {
|
||||
foreach ($data['values'] as $value => $count) {
|
||||
echo "$metric>>$value>>$count".PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints the source of all errors and warnings.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
$metrics = [];
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode('>>', $line);
|
||||
$metric = $parts[0];
|
||||
$value = $parts[1];
|
||||
$count = $parts[2];
|
||||
if (isset($metrics[$metric]) === false) {
|
||||
$metrics[$metric] = [];
|
||||
}
|
||||
|
||||
if (isset($metrics[$metric][$value]) === false) {
|
||||
$metrics[$metric][$value] = $count;
|
||||
} else {
|
||||
$metrics[$metric][$value] += $count;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($metrics);
|
||||
|
||||
echo PHP_EOL."\033[1m".'PHP CODE SNIFFER INFORMATION REPORT'."\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', 70).PHP_EOL;
|
||||
|
||||
foreach ($metrics as $metric => $values) {
|
||||
$winner = '';
|
||||
$winnerCount = 0;
|
||||
$totalCount = 0;
|
||||
foreach ($values as $value => $count) {
|
||||
$totalCount += $count;
|
||||
if ($count > $winnerCount) {
|
||||
$winner = $value;
|
||||
$winnerCount = $count;
|
||||
}
|
||||
}
|
||||
|
||||
$winPercent = round(($winnerCount / $totalCount * 100), 2);
|
||||
echo "$metric: \033[4m$winner\033[0m [$winnerCount/$totalCount, $winPercent%]".PHP_EOL;
|
||||
|
||||
asort($values);
|
||||
$values = array_reverse($values, true);
|
||||
foreach ($values as $value => $count) {
|
||||
if ($value === $winner) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$percent = round(($count / $totalCount * 100), 2);
|
||||
echo "\t$value => $count ($percent%)".PHP_EOL;
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', 70).PHP_EOL;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
111
vendor/squizlabs/php_codesniffer/src/Reports/Json.php
vendored
Normal file
111
vendor/squizlabs/php_codesniffer/src/Reports/Json.php
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* JSON report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Jeffrey Fisher <jeffslofish@gmail.com>
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Json implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$filename = str_replace('\\', '\\\\', $report['filename']);
|
||||
$filename = str_replace('"', '\"', $filename);
|
||||
$filename = str_replace('/', '\/', $filename);
|
||||
echo '"'.$filename.'":{';
|
||||
echo '"errors":'.$report['errors'].',"warnings":'.$report['warnings'].',"messages":[';
|
||||
|
||||
$messages = '';
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$error['message'] = str_replace('\\', '\\\\', $error['message']);
|
||||
$error['message'] = str_replace('"', '\"', $error['message']);
|
||||
$error['message'] = str_replace('/', '\/', $error['message']);
|
||||
$error['message'] = str_replace("\n", '\n', $error['message']);
|
||||
$error['message'] = str_replace("\r", '\r', $error['message']);
|
||||
$error['message'] = str_replace("\t", '\t', $error['message']);
|
||||
|
||||
$fixable = 'false';
|
||||
if ($error['fixable'] === true) {
|
||||
$fixable = 'true';
|
||||
}
|
||||
|
||||
$messages .= '{"message":"'.$error['message'].'",';
|
||||
$messages .= '"source":"'.$error['source'].'",';
|
||||
$messages .= '"severity":'.$error['severity'].',';
|
||||
$messages .= '"type":"'.$error['type'].'",';
|
||||
$messages .= '"line":'.$line.',';
|
||||
$messages .= '"column":'.$column.',';
|
||||
$messages .= '"fixable":'.$fixable;
|
||||
$messages .= '},';
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
|
||||
echo rtrim($messages, ',');
|
||||
echo ']},';
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Generates a JSON report.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
echo '{"totals":{"errors":'.$totalErrors.',"warnings":'.$totalWarnings.',"fixable":'.$totalFixable.'},"files":{';
|
||||
echo rtrim($cachedData, ',');
|
||||
echo "}}";
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
130
vendor/squizlabs/php_codesniffer/src/Reports/Junit.php
vendored
Normal file
130
vendor/squizlabs/php_codesniffer/src/Reports/Junit.php
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* JUnit report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Oleg Lobach <oleg@lobach.info>
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Config;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Junit implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$out = new \XMLWriter;
|
||||
$out->openMemory();
|
||||
$out->setIndent(true);
|
||||
|
||||
$out->startElement('testsuite');
|
||||
$out->writeAttribute('name', $report['filename']);
|
||||
|
||||
if (count($report['messages']) === 0) {
|
||||
$out->writeAttribute('tests', 1);
|
||||
$out->writeAttribute('failures', 0);
|
||||
|
||||
$out->startElement('testcase');
|
||||
$out->writeAttribute('name', $report['filename']);
|
||||
$out->endElement();
|
||||
} else {
|
||||
$failures = ($report['errors'] + $report['warnings']);
|
||||
$out->writeAttribute('tests', $failures);
|
||||
$out->writeAttribute('failures', $failures);
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$out->startElement('testcase');
|
||||
$out->writeAttribute('name', $error['source'].' at '.$report['filename']." ($line:$column)");
|
||||
|
||||
$error['type'] = strtolower($error['type']);
|
||||
if ($phpcsFile->config->encoding !== 'utf-8') {
|
||||
$error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
|
||||
}
|
||||
|
||||
$out->startElement('failure');
|
||||
$out->writeAttribute('type', $error['type']);
|
||||
$out->writeAttribute('message', $error['message']);
|
||||
$out->endElement();
|
||||
|
||||
$out->endElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
|
||||
$out->endElement();
|
||||
echo $out->flush();
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints all violations for processed files, in a proprietary XML format.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
// Figure out the total number of tests.
|
||||
$tests = 0;
|
||||
$matches = [];
|
||||
preg_match_all('/tests="([0-9]+)"/', $cachedData, $matches);
|
||||
if (isset($matches[1]) === true) {
|
||||
foreach ($matches[1] as $match) {
|
||||
$tests += $match;
|
||||
}
|
||||
}
|
||||
|
||||
$failures = ($totalErrors + $totalWarnings);
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
|
||||
echo '<testsuites name="PHP_CodeSniffer '.Config::VERSION.'" tests="'.$tests.'" failures="'.$failures.'">'.PHP_EOL;
|
||||
echo $cachedData;
|
||||
echo '</testsuites>'.PHP_EOL;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
241
vendor/squizlabs/php_codesniffer/src/Reports/Notifysend.php
vendored
Normal file
241
vendor/squizlabs/php_codesniffer/src/Reports/Notifysend.php
vendored
Normal file
@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* Notify-send report for PHP_CodeSniffer.
|
||||
*
|
||||
* Supported configuration parameters:
|
||||
* - notifysend_path - Full path to notify-send cli command
|
||||
* - notifysend_timeout - Timeout in milliseconds
|
||||
* - notifysend_showok - Show "ok, all fine" messages (0/1)
|
||||
*
|
||||
* @author Christian Weiske <christian.weiske@netresearch.de>
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2012-2014 Christian Weiske
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Config;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Notifysend implements Report
|
||||
{
|
||||
|
||||
/**
|
||||
* Notification timeout in milliseconds.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $timeout = 3000;
|
||||
|
||||
/**
|
||||
* Path to notify-send command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path = 'notify-send';
|
||||
|
||||
/**
|
||||
* Show "ok, all fine" messages.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $showOk = true;
|
||||
|
||||
/**
|
||||
* Version of installed notify-send executable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $version = null;
|
||||
|
||||
|
||||
/**
|
||||
* Load configuration data.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$path = Config::getExecutablePath('notifysend');
|
||||
if ($path !== null) {
|
||||
$this->path = escapeshellcmd($path);
|
||||
}
|
||||
|
||||
$timeout = Config::getConfigData('notifysend_timeout');
|
||||
if ($timeout !== null) {
|
||||
$this->timeout = (int) $timeout;
|
||||
}
|
||||
|
||||
$showOk = Config::getConfigData('notifysend_showok');
|
||||
if ($showOk !== null) {
|
||||
$this->showOk = (boolean) $showOk;
|
||||
}
|
||||
|
||||
$this->version = str_replace(
|
||||
'notify-send ',
|
||||
'',
|
||||
exec($this->path.' --version')
|
||||
);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
echo $report['filename'].PHP_EOL;
|
||||
|
||||
// We want this file counted in the total number
|
||||
// of checked files even if it has no errors.
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Generates a summary of errors and warnings for each file processed.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
$checkedFiles = explode(PHP_EOL, trim($cachedData));
|
||||
|
||||
$msg = $this->generateMessage($checkedFiles, $totalErrors, $totalWarnings);
|
||||
if ($msg === null) {
|
||||
if ($this->showOk === true) {
|
||||
$this->notifyAllFine();
|
||||
}
|
||||
} else {
|
||||
$this->notifyErrors($msg);
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Generate the error message to show to the user.
|
||||
*
|
||||
* @param string[] $checkedFiles The files checked during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
*
|
||||
* @return string Error message or NULL if no error/warning found.
|
||||
*/
|
||||
protected function generateMessage($checkedFiles, $totalErrors, $totalWarnings)
|
||||
{
|
||||
if ($totalErrors === 0 && $totalWarnings === 0) {
|
||||
// Nothing to print.
|
||||
return null;
|
||||
}
|
||||
|
||||
$totalFiles = count($checkedFiles);
|
||||
|
||||
$msg = '';
|
||||
if ($totalFiles > 1) {
|
||||
$msg .= 'Checked '.$totalFiles.' files'.PHP_EOL;
|
||||
} else {
|
||||
$msg .= $checkedFiles[0].PHP_EOL;
|
||||
}
|
||||
|
||||
if ($totalWarnings > 0) {
|
||||
$msg .= $totalWarnings.' warnings'.PHP_EOL;
|
||||
}
|
||||
|
||||
if ($totalErrors > 0) {
|
||||
$msg .= $totalErrors.' errors'.PHP_EOL;
|
||||
}
|
||||
|
||||
return $msg;
|
||||
|
||||
}//end generateMessage()
|
||||
|
||||
|
||||
/**
|
||||
* Tell the user that all is fine and no error/warning has been found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function notifyAllFine()
|
||||
{
|
||||
$cmd = $this->getBasicCommand();
|
||||
$cmd .= ' -i info';
|
||||
$cmd .= ' "PHP CodeSniffer: Ok"';
|
||||
$cmd .= ' "All fine"';
|
||||
exec($cmd);
|
||||
|
||||
}//end notifyAllFine()
|
||||
|
||||
|
||||
/**
|
||||
* Tell the user that errors/warnings have been found.
|
||||
*
|
||||
* @param string $msg Message to display.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function notifyErrors($msg)
|
||||
{
|
||||
$cmd = $this->getBasicCommand();
|
||||
$cmd .= ' -i error';
|
||||
$cmd .= ' "PHP CodeSniffer: Error"';
|
||||
$cmd .= ' '.escapeshellarg(trim($msg));
|
||||
exec($cmd);
|
||||
|
||||
}//end notifyErrors()
|
||||
|
||||
|
||||
/**
|
||||
* Generate and return the basic notify-send command string to execute.
|
||||
*
|
||||
* @return string Shell command with common parameters.
|
||||
*/
|
||||
protected function getBasicCommand()
|
||||
{
|
||||
$cmd = $this->path;
|
||||
$cmd .= ' --category dev.validate';
|
||||
$cmd .= ' -h int:transient:1';
|
||||
$cmd .= ' -t '.(int) $this->timeout;
|
||||
if (version_compare($this->version, '0.7.3', '>=') === true) {
|
||||
$cmd .= ' -a phpcs';
|
||||
}
|
||||
|
||||
return $cmd;
|
||||
|
||||
}//end getBasicCommand()
|
||||
|
||||
|
||||
}//end class
|
64
vendor/squizlabs/php_codesniffer/src/Reports/Report.php
vendored
Normal file
64
vendor/squizlabs/php_codesniffer/src/Reports/Report.php
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* An interface that PHP_CodeSniffer reports must implement.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
interface Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80);
|
||||
|
||||
|
||||
/**
|
||||
* Generate the actual report.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
);
|
||||
|
||||
|
||||
}//end interface
|
337
vendor/squizlabs/php_codesniffer/src/Reports/Source.php
vendored
Normal file
337
vendor/squizlabs/php_codesniffer/src/Reports/Source.php
vendored
Normal file
@ -0,0 +1,337 @@
|
||||
<?php
|
||||
/**
|
||||
* Source report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util\Timing;
|
||||
|
||||
class Source implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
$sources = [];
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$src = $error['source'];
|
||||
if (isset($sources[$src]) === false) {
|
||||
$sources[$src] = [
|
||||
'fixable' => (int) $error['fixable'],
|
||||
'count' => 1,
|
||||
];
|
||||
} else {
|
||||
$sources[$src]['count']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($sources as $source => $data) {
|
||||
echo $source.'>>'.$data['fixable'].'>>'.$data['count'].PHP_EOL;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints the source of all errors and warnings.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
$sources = [];
|
||||
$maxLength = 0;
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode('>>', $line);
|
||||
$source = $parts[0];
|
||||
$fixable = (bool) $parts[1];
|
||||
$count = $parts[2];
|
||||
|
||||
if (isset($sources[$source]) === false) {
|
||||
if ($showSources === true) {
|
||||
$parts = null;
|
||||
$sniff = $source;
|
||||
} else {
|
||||
$parts = explode('.', $source);
|
||||
if ($parts[0] === 'Internal') {
|
||||
$parts[2] = $parts[1];
|
||||
$parts[1] = '';
|
||||
}
|
||||
|
||||
$parts[1] = $this->makeFriendlyName($parts[1]);
|
||||
|
||||
$sniff = $this->makeFriendlyName($parts[2]);
|
||||
if (isset($parts[3]) === true) {
|
||||
$name = $this->makeFriendlyName($parts[3]);
|
||||
$name[0] = strtolower($name[0]);
|
||||
$sniff .= ' '.$name;
|
||||
unset($parts[3]);
|
||||
}
|
||||
|
||||
$parts[2] = $sniff;
|
||||
}//end if
|
||||
|
||||
$maxLength = max($maxLength, strlen($sniff));
|
||||
|
||||
$sources[$source] = [
|
||||
'count' => $count,
|
||||
'fixable' => $fixable,
|
||||
'parts' => $parts,
|
||||
];
|
||||
} else {
|
||||
$sources[$source]['count'] += $count;
|
||||
}//end if
|
||||
|
||||
$fileLen = strlen($parts[0]);
|
||||
$reportFiles[$parts[0]] = [
|
||||
'errors' => $parts[1],
|
||||
'warnings' => $parts[2],
|
||||
'strlen' => $fileLen,
|
||||
];
|
||||
}//end foreach
|
||||
|
||||
if ($showSources === true) {
|
||||
$width = min($width, ($maxLength + 11));
|
||||
} else {
|
||||
$width = min($width, ($maxLength + 41));
|
||||
}
|
||||
|
||||
$width = max($width, 70);
|
||||
|
||||
asort($sources);
|
||||
$sources = array_reverse($sources);
|
||||
|
||||
echo PHP_EOL."\033[1mPHP CODE SNIFFER VIOLATION SOURCE SUMMARY\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL."\033[1m";
|
||||
if ($showSources === true) {
|
||||
if ($totalFixable > 0) {
|
||||
echo ' SOURCE'.str_repeat(' ', ($width - 15)).'COUNT'.PHP_EOL;
|
||||
} else {
|
||||
echo 'SOURCE'.str_repeat(' ', ($width - 11)).'COUNT'.PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
if ($totalFixable > 0) {
|
||||
echo ' STANDARD CATEGORY SNIFF'.str_repeat(' ', ($width - 44)).'COUNT'.PHP_EOL;
|
||||
} else {
|
||||
echo 'STANDARD CATEGORY SNIFF'.str_repeat(' ', ($width - 40)).'COUNT'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
echo "\033[0m".str_repeat('-', $width).PHP_EOL;
|
||||
|
||||
$fixableSources = 0;
|
||||
|
||||
if ($showSources === true) {
|
||||
$maxSniffWidth = ($width - 7);
|
||||
} else {
|
||||
$maxSniffWidth = ($width - 37);
|
||||
}
|
||||
|
||||
if ($totalFixable > 0) {
|
||||
$maxSniffWidth -= 4;
|
||||
}
|
||||
|
||||
foreach ($sources as $source => $sourceData) {
|
||||
if ($totalFixable > 0) {
|
||||
echo '[';
|
||||
if ($sourceData['fixable'] === true) {
|
||||
echo 'x';
|
||||
$fixableSources++;
|
||||
} else {
|
||||
echo ' ';
|
||||
}
|
||||
|
||||
echo '] ';
|
||||
}
|
||||
|
||||
if ($showSources === true) {
|
||||
if (strlen($source) > $maxSniffWidth) {
|
||||
$source = substr($source, 0, $maxSniffWidth);
|
||||
}
|
||||
|
||||
echo $source;
|
||||
if ($totalFixable > 0) {
|
||||
echo str_repeat(' ', ($width - 9 - strlen($source)));
|
||||
} else {
|
||||
echo str_repeat(' ', ($width - 5 - strlen($source)));
|
||||
}
|
||||
} else {
|
||||
$parts = $sourceData['parts'];
|
||||
|
||||
if (strlen($parts[0]) > 8) {
|
||||
$parts[0] = substr($parts[0], 0, ((strlen($parts[0]) - 8) * -1));
|
||||
}
|
||||
|
||||
echo $parts[0].str_repeat(' ', (10 - strlen($parts[0])));
|
||||
|
||||
$category = $parts[1];
|
||||
if (strlen($category) > 18) {
|
||||
$category = substr($category, 0, ((strlen($category) - 18) * -1));
|
||||
}
|
||||
|
||||
echo $category.str_repeat(' ', (20 - strlen($category)));
|
||||
|
||||
$sniff = $parts[2];
|
||||
if (strlen($sniff) > $maxSniffWidth) {
|
||||
$sniff = substr($sniff, 0, $maxSniffWidth);
|
||||
}
|
||||
|
||||
if ($totalFixable > 0) {
|
||||
echo $sniff.str_repeat(' ', ($width - 39 - strlen($sniff)));
|
||||
} else {
|
||||
echo $sniff.str_repeat(' ', ($width - 35 - strlen($sniff)));
|
||||
}
|
||||
}//end if
|
||||
|
||||
echo $sourceData['count'].PHP_EOL;
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1m".'A TOTAL OF '.($totalErrors + $totalWarnings).' SNIFF VIOLATION';
|
||||
if (($totalErrors + $totalWarnings) > 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo ' WERE FOUND IN '.count($sources).' SOURCE';
|
||||
if (count($sources) !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo "\033[0m";
|
||||
|
||||
if ($totalFixable > 0) {
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1mPHPCBF CAN FIX THE $fixableSources MARKED SOURCES AUTOMATICALLY ($totalFixable VIOLATIONS IN TOTAL)\033[0m";
|
||||
}
|
||||
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Converts a camel caps name into a readable string.
|
||||
*
|
||||
* @param string $name The camel caps name to convert.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function makeFriendlyName($name)
|
||||
{
|
||||
if (trim($name) === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$friendlyName = '';
|
||||
$length = strlen($name);
|
||||
|
||||
$lastWasUpper = false;
|
||||
$lastWasNumeric = false;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (is_numeric($name[$i]) === true) {
|
||||
if ($lastWasNumeric === false) {
|
||||
$friendlyName .= ' ';
|
||||
}
|
||||
|
||||
$lastWasUpper = false;
|
||||
$lastWasNumeric = true;
|
||||
} else {
|
||||
$lastWasNumeric = false;
|
||||
|
||||
$char = strtolower($name[$i]);
|
||||
if ($char === $name[$i]) {
|
||||
// Lowercase.
|
||||
$lastWasUpper = false;
|
||||
} else {
|
||||
// Uppercase.
|
||||
if ($lastWasUpper === false) {
|
||||
$friendlyName .= ' ';
|
||||
if ($i < ($length - 1)) {
|
||||
$next = $name[($i + 1)];
|
||||
if (strtolower($next) === $next) {
|
||||
// Next char is lowercase so it is a word boundary.
|
||||
$name[$i] = strtolower($name[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$lastWasUpper = true;
|
||||
}
|
||||
}//end if
|
||||
|
||||
$friendlyName .= $name[$i];
|
||||
}//end for
|
||||
|
||||
$friendlyName = trim($friendlyName);
|
||||
$friendlyName[0] = strtoupper($friendlyName[0]);
|
||||
|
||||
return $friendlyName;
|
||||
|
||||
}//end makeFriendlyName()
|
||||
|
||||
|
||||
}//end class
|
162
vendor/squizlabs/php_codesniffer/src/Reports/Summary.php
vendored
Normal file
162
vendor/squizlabs/php_codesniffer/src/Reports/Summary.php
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Summary report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util;
|
||||
|
||||
class Summary implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
if (PHP_CODESNIFFER_VERBOSITY === 0
|
||||
&& $report['errors'] === 0
|
||||
&& $report['warnings'] === 0
|
||||
) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
echo $report['filename'].'>>'.$report['errors'].'>>'.$report['warnings'].PHP_EOL;
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Generates a summary of errors and warnings for each file processed.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
$width = min($width, ($maxLength + 21));
|
||||
$width = max($width, 70);
|
||||
|
||||
echo PHP_EOL."\033[1m".'PHP CODE SNIFFER REPORT SUMMARY'."\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'ERRORS WARNINGS'."\033[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 "\033[31m".$data['errors']."\033[0m";
|
||||
echo str_repeat(' ', (8 - strlen((string) $data['errors'])));
|
||||
} else {
|
||||
echo '0 ';
|
||||
}
|
||||
|
||||
if ($data['warnings'] !== 0) {
|
||||
echo "\033[33m".$data['warnings']."\033[0m";
|
||||
} else {
|
||||
echo '0';
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[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 "\033[0m";
|
||||
|
||||
if ($totalFixable > 0) {
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1mPHPCBF CAN FIX $totalFixable OF THESE SNIFF VIOLATIONS AUTOMATICALLY\033[0m";
|
||||
}
|
||||
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Util\Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
72
vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php
vendored
Normal file
72
vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* SVN blame report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Exceptions\DeepExitException;
|
||||
|
||||
class Svnblame extends VersionControl
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the report we want in the output
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reportName = 'SVN';
|
||||
|
||||
|
||||
/**
|
||||
* Extract the author from a blame line.
|
||||
*
|
||||
* @param string $line Line to parse.
|
||||
*
|
||||
* @return mixed string or false if impossible to recover.
|
||||
*/
|
||||
protected function getAuthor($line)
|
||||
{
|
||||
$blameParts = [];
|
||||
preg_match('|\s*([^\s]+)\s+([^\s]+)|', $line, $blameParts);
|
||||
|
||||
if (isset($blameParts[2]) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $blameParts[2];
|
||||
|
||||
}//end getAuthor()
|
||||
|
||||
|
||||
/**
|
||||
* Gets the blame output.
|
||||
*
|
||||
* @param string $filename File to blame.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBlameContent($filename)
|
||||
{
|
||||
$command = 'svn blame "'.$filename.'" 2>&1';
|
||||
$handle = popen($command, 'r');
|
||||
if ($handle === false) {
|
||||
$error = 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
|
||||
throw new DeepExitException($error, 3);
|
||||
}
|
||||
|
||||
$rawContent = stream_get_contents($handle);
|
||||
fclose($handle);
|
||||
|
||||
$blames = explode("\n", $rawContent);
|
||||
|
||||
return $blames;
|
||||
|
||||
}//end getBlameContent()
|
||||
|
||||
|
||||
}//end class
|
376
vendor/squizlabs/php_codesniffer/src/Reports/VersionControl.php
vendored
Normal file
376
vendor/squizlabs/php_codesniffer/src/Reports/VersionControl.php
vendored
Normal file
@ -0,0 +1,376 @@
|
||||
<?php
|
||||
/**
|
||||
* Version control report base class for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Ben Selby <benmatselby@gmail.com>
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util\Timing;
|
||||
|
||||
abstract class VersionControl implements Report
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the report we want in the output.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reportName = 'VERSION CONTROL';
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$blames = $this->getBlameContent($report['filename']);
|
||||
|
||||
$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 $column => $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;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints the author of all errors and warnings, as given by "version control blame".
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
$errorsShown = ($totalErrors + $totalWarnings);
|
||||
if ($errorsShown === 0) {
|
||||
// Nothing to show.
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = explode(PHP_EOL, $cachedData);
|
||||
array_pop($lines);
|
||||
|
||||
if (empty($lines) === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$authorCache = [];
|
||||
$praiseCache = [];
|
||||
$sourceCache = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode('>>', $line);
|
||||
switch ($parts[0]) {
|
||||
case 'AUTHOR':
|
||||
if (isset($authorCache[$parts[1]]) === false) {
|
||||
$authorCache[$parts[1]] = $parts[2];
|
||||
} else {
|
||||
$authorCache[$parts[1]] += $parts[2];
|
||||
}
|
||||
break;
|
||||
case 'PRAISE':
|
||||
if (isset($praiseCache[$parts[1]]) === false) {
|
||||
$praiseCache[$parts[1]] = [
|
||||
'good' => $parts[2],
|
||||
'bad' => $parts[3],
|
||||
];
|
||||
} else {
|
||||
$praiseCache[$parts[1]]['good'] += $parts[2];
|
||||
$praiseCache[$parts[1]]['bad'] += $parts[3];
|
||||
}
|
||||
break;
|
||||
case 'SOURCE':
|
||||
if (isset($praiseCache[$parts[1]]) === false) {
|
||||
$praiseCache[$parts[1]] = [];
|
||||
}
|
||||
|
||||
if (isset($sourceCache[$parts[1]][$parts[2]]) === false) {
|
||||
$sourceCache[$parts[1]][$parts[2]] = [
|
||||
'count' => $parts[3],
|
||||
'fixable' => (bool) $parts[4],
|
||||
];
|
||||
} else {
|
||||
$sourceCache[$parts[1]][$parts[2]]['count'] += $parts[3];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}//end switch
|
||||
}//end foreach
|
||||
|
||||
// Make sure the report width isn't too big.
|
||||
$maxLength = 0;
|
||||
foreach ($authorCache as $author => $count) {
|
||||
$maxLength = max($maxLength, strlen($author));
|
||||
if ($showSources === true && isset($sourceCache[$author]) === true) {
|
||||
foreach ($sourceCache[$author] as $source => $sourceData) {
|
||||
if ($source === 'count') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$maxLength = max($maxLength, (strlen($source) + 9));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$width = min($width, ($maxLength + 30));
|
||||
$width = max($width, 70);
|
||||
arsort($authorCache);
|
||||
|
||||
echo PHP_EOL."\033[1m".'PHP CODE SNIFFER '.$this->reportName.' BLAME SUMMARY'."\033[0m".PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL."\033[1m";
|
||||
if ($showSources === true) {
|
||||
echo 'AUTHOR SOURCE'.str_repeat(' ', ($width - 43)).'(Author %) (Overall %) COUNT'.PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
} else {
|
||||
echo 'AUTHOR'.str_repeat(' ', ($width - 34)).'(Author %) (Overall %) COUNT'.PHP_EOL;
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
}
|
||||
|
||||
echo "\033[0m";
|
||||
|
||||
if ($showSources === true) {
|
||||
$maxSniffWidth = ($width - 15);
|
||||
|
||||
if ($totalFixable > 0) {
|
||||
$maxSniffWidth -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
$fixableSources = 0;
|
||||
|
||||
foreach ($authorCache as $author => $count) {
|
||||
if ($praiseCache[$author]['good'] === 0) {
|
||||
$percent = 0;
|
||||
} else {
|
||||
$total = ($praiseCache[$author]['bad'] + $praiseCache[$author]['good']);
|
||||
$percent = round(($praiseCache[$author]['bad'] / $total * 100), 2);
|
||||
}
|
||||
|
||||
$overallPercent = '('.round((($count / $errorsShown) * 100), 2).')';
|
||||
$authorPercent = '('.$percent.')';
|
||||
$line = str_repeat(' ', (6 - strlen($count))).$count;
|
||||
$line = str_repeat(' ', (12 - strlen($overallPercent))).$overallPercent.$line;
|
||||
$line = str_repeat(' ', (11 - strlen($authorPercent))).$authorPercent.$line;
|
||||
$line = $author.str_repeat(' ', ($width - strlen($author) - strlen($line))).$line;
|
||||
|
||||
if ($showSources === true) {
|
||||
$line = "\033[1m$line\033[0m";
|
||||
}
|
||||
|
||||
echo $line.PHP_EOL;
|
||||
|
||||
if ($showSources === true && isset($sourceCache[$author]) === true) {
|
||||
$errors = $sourceCache[$author];
|
||||
asort($errors);
|
||||
$errors = array_reverse($errors);
|
||||
|
||||
foreach ($errors as $source => $sourceData) {
|
||||
if ($source === 'count') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$count = $sourceData['count'];
|
||||
|
||||
$srcLength = strlen($source);
|
||||
if ($srcLength > $maxSniffWidth) {
|
||||
$source = substr($source, 0, $maxSniffWidth);
|
||||
}
|
||||
|
||||
$line = str_repeat(' ', (5 - strlen($count))).$count;
|
||||
|
||||
echo ' ';
|
||||
if ($totalFixable > 0) {
|
||||
echo '[';
|
||||
if ($sourceData['fixable'] === true) {
|
||||
echo 'x';
|
||||
$fixableSources++;
|
||||
} else {
|
||||
echo ' ';
|
||||
}
|
||||
|
||||
echo '] ';
|
||||
}
|
||||
|
||||
echo $source;
|
||||
if ($totalFixable > 0) {
|
||||
echo str_repeat(' ', ($width - 18 - strlen($source)));
|
||||
} else {
|
||||
echo str_repeat(' ', ($width - 14 - strlen($source)));
|
||||
}
|
||||
|
||||
echo $line.PHP_EOL;
|
||||
}//end foreach
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
echo str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1m".'A TOTAL OF '.$errorsShown.' SNIFF VIOLATION';
|
||||
if ($errorsShown !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo ' WERE COMMITTED BY '.count($authorCache).' AUTHOR';
|
||||
if (count($authorCache) !== 1) {
|
||||
echo 'S';
|
||||
}
|
||||
|
||||
echo "\033[0m";
|
||||
|
||||
if ($totalFixable > 0) {
|
||||
if ($showSources === true) {
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1mPHPCBF CAN FIX THE $fixableSources MARKED SOURCES AUTOMATICALLY ($totalFixable VIOLATIONS IN TOTAL)\033[0m";
|
||||
} else {
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
|
||||
echo "\033[1mPHPCBF CAN FIX $totalFixable OF THESE SNIFF VIOLATIONS AUTOMATICALLY\033[0m";
|
||||
}
|
||||
}
|
||||
|
||||
echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
|
||||
|
||||
if ($toScreen === true && $interactive === false) {
|
||||
Timing::printRunTime();
|
||||
}
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
/**
|
||||
* Extract the author from a blame line.
|
||||
*
|
||||
* @param string $line Line to parse.
|
||||
*
|
||||
* @return mixed string or false if impossible to recover.
|
||||
*/
|
||||
abstract protected function getAuthor($line);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the blame output.
|
||||
*
|
||||
* @param string $filename File to blame.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getBlameContent($filename);
|
||||
|
||||
|
||||
}//end class
|
121
vendor/squizlabs/php_codesniffer/src/Reports/Xml.php
vendored
Normal file
121
vendor/squizlabs/php_codesniffer/src/Reports/Xml.php
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* XML report for PHP_CodeSniffer.
|
||||
*
|
||||
* @author Greg Sherwood <gsherwood@squiz.net>
|
||||
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
|
||||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
||||
*/
|
||||
|
||||
namespace PHP_CodeSniffer\Reports;
|
||||
|
||||
use PHP_CodeSniffer\Config;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Xml implements Report
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array $report Prepared report data.
|
||||
* @param \PHP_CodeSniffer\File $phpcsFile The file being reported on.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
|
||||
{
|
||||
$out = new \XMLWriter;
|
||||
$out->openMemory();
|
||||
$out->setIndent(true);
|
||||
$out->setIndentString(' ');
|
||||
$out->startDocument('1.0', 'UTF-8');
|
||||
|
||||
if ($report['errors'] === 0 && $report['warnings'] === 0) {
|
||||
// Nothing to print.
|
||||
return false;
|
||||
}
|
||||
|
||||
$out->startElement('file');
|
||||
$out->writeAttribute('name', $report['filename']);
|
||||
$out->writeAttribute('errors', $report['errors']);
|
||||
$out->writeAttribute('warnings', $report['warnings']);
|
||||
$out->writeAttribute('fixable', $report['fixable']);
|
||||
|
||||
foreach ($report['messages'] as $line => $lineErrors) {
|
||||
foreach ($lineErrors as $column => $colErrors) {
|
||||
foreach ($colErrors as $error) {
|
||||
$error['type'] = strtolower($error['type']);
|
||||
if ($phpcsFile->config->encoding !== 'utf-8') {
|
||||
$error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
|
||||
}
|
||||
|
||||
$out->startElement($error['type']);
|
||||
$out->writeAttribute('line', $line);
|
||||
$out->writeAttribute('column', $column);
|
||||
$out->writeAttribute('source', $error['source']);
|
||||
$out->writeAttribute('severity', $error['severity']);
|
||||
$out->writeAttribute('fixable', (int) $error['fixable']);
|
||||
$out->text($error['message']);
|
||||
$out->endElement();
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$out->endElement();
|
||||
|
||||
// Remove the start of the document because we will
|
||||
// add that manually later. We only have it in here to
|
||||
// properly set the encoding.
|
||||
$content = $out->flush();
|
||||
$content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL)));
|
||||
echo $content;
|
||||
|
||||
return true;
|
||||
|
||||
}//end generateFileReport()
|
||||
|
||||
|
||||
/**
|
||||
* Prints all violations for processed files, in a proprietary XML format.
|
||||
*
|
||||
* @param string $cachedData Any partial report data that was returned from
|
||||
* generateFileReport during the run.
|
||||
* @param int $totalFiles Total number of files processed during the run.
|
||||
* @param int $totalErrors Total number of errors found during the run.
|
||||
* @param int $totalWarnings Total number of warnings found during the run.
|
||||
* @param int $totalFixable Total number of problems that can be fixed.
|
||||
* @param bool $showSources Show sources?
|
||||
* @param int $width Maximum allowed line width.
|
||||
* @param bool $interactive Are we running in interactive mode?
|
||||
* @param bool $toScreen Is the report being printed to screen?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate(
|
||||
$cachedData,
|
||||
$totalFiles,
|
||||
$totalErrors,
|
||||
$totalWarnings,
|
||||
$totalFixable,
|
||||
$showSources=false,
|
||||
$width=80,
|
||||
$interactive=false,
|
||||
$toScreen=true
|
||||
) {
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
|
||||
echo '<phpcs version="'.Config::VERSION.'">'.PHP_EOL;
|
||||
echo $cachedData;
|
||||
echo '</phpcs>'.PHP_EOL;
|
||||
|
||||
}//end generate()
|
||||
|
||||
|
||||
}//end class
|
Reference in New Issue
Block a user