Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,104 @@
<?php
/**
* Checkstyle report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Checkstyle report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Checkstyle implements PHP_CodeSniffer_Report
{
/**
* Prints all violations for processed files, in a Checkstyle format.
*
* Violations are grouped by file.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$out = new XMLWriter;
$out->openMemory();
$out->setIndent(true);
$out->startDocument('1.0', 'UTF-8');
$out->startElement('checkstyle');
$out->writeAttribute('version', '1.3.3');
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
if (count($file['messages']) === 0) {
continue;
}
$out->startElement('file');
$out->writeAttribute('name', $filename);
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$error['type'] = strtolower($error['type']);
if (PHP_CODESNIFFER_ENCODING !== 'utf-8') {
$error['message'] = iconv(PHP_CODESNIFFER_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();
$errorsShown++;
}
}
}//end foreach
$out->endElement();
}//end foreach
$out->endElement();
echo $out->flush();
return $errorsShown;
}//end generate()
}//end class
?>

View File

@@ -0,0 +1,78 @@
<?php
/**
* Csv report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Csv report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Csv implements PHP_CodeSniffer_Report
{
/**
* Generates a csv report.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
echo 'File,Line,Column,Type,Message,Source,Severity'.PHP_EOL;
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$filename = str_replace('"', '\"', $filename);
$message = str_replace('"', '\"', $error['message']);
$type = strtolower($error['type']);
$source = $error['source'];
$severity = $error['severity'];
echo "\"$filename\",$line,$column,$type,\"$message\",$source,$severity".PHP_EOL;
$errorsShown++;
}
}
}//end foreach
}//end foreach
return $errorsShown;
}//end generate()
}//end class
?>

View File

@@ -0,0 +1,78 @@
<?php
/**
* Emacs report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Emacs report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Emacs implements PHP_CodeSniffer_Report
{
/**
* Generates an emacs report.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
foreach ($file['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 $filename.':'.$line.':'.$column.': '.$type.' - '.$message.PHP_EOL;
$errorsShown++;
}
}
}//end foreach
}//end foreach
return $errorsShown;
}//end generate()
}//end class
?>

View File

@@ -0,0 +1,153 @@
<?php
/**
* Full report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Full report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Full implements PHP_CodeSniffer_Report
{
/**
* Prints all errors and warnings for each file processed.
*
* Errors and warnings are displayed together, grouped by file.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$errorsShown = 0;
$width = max($width, 70);
foreach ($report['files'] as $filename => $file) {
if (empty($file['messages']) === true) {
continue;
}
echo PHP_EOL.'FILE: ';
if (strlen($filename) <= ($width - 9)) {
echo $filename;
} else {
echo '...'.substr($filename, (strlen($filename) - ($width - 9)));
}
echo PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
echo 'FOUND '.$file['errors'].' ERROR(S) ';
if ($file['warnings'] > 0) {
echo 'AND '.$file['warnings'].' WARNING(S) ';
}
echo 'AFFECTING '.count($file['messages']).' LINE(S)'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
// Work out the max line number for formatting.
$maxLine = 0;
foreach ($file['messages'] as $line => $lineErrors) {
if ($line > $maxLine) {
$maxLine = $line;
}
}
$maxLineLength = strlen($maxLine);
// The length of the word ERROR or WARNING; used for padding.
if ($file['warnings'] > 0) {
$typeLength = 7;
} else {
$typeLength = 5;
}
// The padding that all lines will require that are
// printing an error message overflow.
$paddingLine2 = str_repeat(' ', ($maxLineLength + 1));
$paddingLine2 .= ' | ';
$paddingLine2 .= str_repeat(' ', $typeLength);
$paddingLine2 .= ' | ';
// The maxium amount of space an error message can use.
$maxErrorSpace = ($width - strlen($paddingLine2) - 1);
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$message = $error['message'];
if ($showSources === true) {
$message .= ' ('.$error['source'].')';
}
// The padding that goes on the front of the line.
$padding = ($maxLineLength - strlen($line));
$errorMsg = wordwrap(
$message,
$maxErrorSpace,
PHP_EOL.$paddingLine2
);
echo ' '.str_repeat(' ', $padding).$line.' | '.$error['type'];
if ($error['type'] === 'ERROR') {
if ($file['warnings'] > 0) {
echo ' ';
}
}
echo ' | '.$errorMsg.PHP_EOL;
$errorsShown++;
}//end foreach
}//end foreach
}//end foreach
echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
}//end foreach
if ($toScreen === true
&& PHP_CODESNIFFER_INTERACTIVE === false
&& class_exists('PHP_Timer', false) === true
) {
echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
}
return $errorsShown;
}//end generate()
}//end class
?>

View File

@@ -0,0 +1,133 @@
<?php
/**
* Gitblame report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Gitblame report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.2
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Gitblame extends PHP_CodeSniffer_Reports_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 = array();
$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));
return preg_replace('|\(|', '', implode($parts, ' '));
}//end getAuthor()
/**
* Gets the blame output.
*
* @param string $filename File to blame.
*
* @return array
*/
protected function getBlameContent($filename)
{
$cwd = getcwd();
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo 'Getting GIT blame info for '.basename($filename).'... ';
}
$fileParts = explode('/', $filename);
$found = false;
$location = '';
while (empty($fileParts) === false) {
array_pop($fileParts);
$location = implode($fileParts, '/');
if (is_dir($location.'/.git') === true) {
$found = true;
break;
}
}
if ($found === true) {
chdir($location);
} else {
echo 'ERROR: Could not locate .git directory '.PHP_EOL.PHP_EOL;
exit(2);
}
$command = 'git blame --date=short '.$filename;
$handle = popen($command, 'r');
if ($handle === false) {
echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
exit(2);
}
$rawContent = stream_get_contents($handle);
fclose($handle);
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo 'DONE'.PHP_EOL;
}
$blames = explode("\n", $rawContent);
chdir($cwd);
return $blames;
}//end getBlameContent()
}//end class
?>

View File

@@ -0,0 +1,134 @@
<?php
/**
* Mercurial report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Mercurial report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Hgblame extends PHP_CodeSniffer_Reports_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 = array();
$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();
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo 'Getting MERCURIAL blame info for '.basename($filename).'... ';
}
$fileParts = explode('/', $filename);
$found = false;
$location = '';
while (empty($fileParts) === false) {
array_pop($fileParts);
$location = implode($fileParts, '/');
if (is_dir($location.'/.hg') === true) {
$found = true;
break;
}
}
if ($found === true) {
chdir($location);
} else {
echo 'ERROR: Could not locate .hg directory '.PHP_EOL.PHP_EOL;
exit(2);
}
$command = 'hg blame -u -d -v '.$filename;
$handle = popen($command, 'r');
if ($handle === false) {
echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
exit(2);
}
$rawContent = stream_get_contents($handle);
fclose($handle);
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo 'DONE'.PHP_EOL;
}
$blames = explode("\n", $rawContent);
chdir($cwd);
return $blames;
}//end getBlameContent()
}//end class
?>

View File

@@ -0,0 +1,202 @@
<?php
/**
* Source report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Source report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Source implements PHP_CodeSniffer_Report
{
/**
* Prints the source of all errors and warnings.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$sources = array();
$width = max($width, 70);
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$errorsShown++;
$source = $error['source'];
if (isset($sources[$source]) === false) {
$sources[$source] = 1;
} else {
$sources[$source]++;
}
}
}
}
}
if ($errorsShown === 0) {
// Nothing to show.
return 0;
}
asort($sources);
$sources = array_reverse($sources);
echo PHP_EOL.'PHP CODE SNIFFER VIOLATION SOURCE SUMMARY'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
if ($showSources === true) {
echo 'SOURCE'.str_repeat(' ', ($width - 11)).'COUNT'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
} else {
echo 'STANDARD CATEGORY SNIFF'.str_repeat(' ', ($width - 40)).'COUNT'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
}
foreach ($sources as $source => $count) {
if ($showSources === true) {
echo $source.str_repeat(' ', ($width - 5 - strlen($source)));
} else {
$parts = explode('.', $source);
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 = $this->makeFriendlyName($parts[1]);
if (strlen($category) > 18) {
$category = substr($category, 0, ((strlen($category) - 18) * -1));
}
echo $category.str_repeat(' ', (20 - strlen($category)));
$sniff = $this->makeFriendlyName($parts[2]);
if (isset($parts[3]) === true) {
$name = $this->makeFriendlyName($parts[3]);
$name[0] = strtolower($name[0]);
$sniff .= ' '.$name;
}
if (strlen($sniff) > ($width - 37)) {
$sniff = substr($sniff, 0, ($width - 37 - strlen($sniff)));
}
echo $sniff.str_repeat(' ', ($width - 35 - strlen($sniff)));
}//end if
echo $count.PHP_EOL;
}//end foreach
echo str_repeat('-', $width).PHP_EOL;
echo 'A TOTAL OF '.$errorsShown.' SNIFF VIOLATION(S) ';
echo 'WERE FOUND IN '.count($sources).' SOURCE(S)'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
if ($toScreen === true
&& PHP_CODESNIFFER_INTERACTIVE === false
&& class_exists('PHP_Timer', false) === true
) {
echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
}
return $errorsShown;
}//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)
{
$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 .= ' ';
$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
?>

View File

@@ -0,0 +1,132 @@
<?php
/**
* Summary report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Summary report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Summary implements PHP_CodeSniffer_Report
{
/**
* Generates a summary of errors and warnings for each file processed.
*
* If verbose output is enabled, results are shown for all files, even if
* they have no errors or warnings. If verbose output is disabled, we only
* show files that have at least one warning or error.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$errorFiles = array();
$width = max($width, 70);
foreach ($report['files'] as $filename => $file) {
$numWarnings = $file['warnings'];
$numErrors = $file['errors'];
// If verbose output is enabled, we show the results for all files,
// but if not, we only show files that had errors or warnings.
if (PHP_CODESNIFFER_VERBOSITY > 0
|| $numErrors > 0
|| $numWarnings > 0
) {
$errorFiles[$filename] = array(
'warnings' => $numWarnings,
'errors' => $numErrors,
);
}//end if
}//end foreach
if (empty($errorFiles) === true) {
// Nothing to print.
return 0;
}
echo PHP_EOL.'PHP CODE SNIFFER REPORT SUMMARY'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
echo 'FILE'.str_repeat(' ', ($width - 20)).'ERRORS WARNINGS'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
$totalErrors = 0;
$totalWarnings = 0;
$totalFiles = 0;
foreach ($errorFiles as $file => $errors) {
$padding = ($width - 18 - strlen($file));
if ($padding < 0) {
$file = '...'.substr($file, (($padding * -1) + 3));
$padding = 0;
}
echo $file.str_repeat(' ', $padding).' ';
echo $errors['errors'];
echo str_repeat(' ', (8 - strlen((string) $errors['errors'])));
echo $errors['warnings'];
echo PHP_EOL;
$totalFiles++;
}//end foreach
echo str_repeat('-', $width).PHP_EOL;
echo 'A TOTAL OF '.$report['totals']['errors'].' ERROR(S) ';
echo 'AND '.$report['totals']['warnings'].' WARNING(S) ';
echo 'WERE FOUND IN '.$totalFiles.' FILE(S)'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
if ($showSources === true) {
$source = new PHP_CodeSniffer_Reports_Source();
$source->generate($report, $showSources, $width);
}
if ($toScreen === true
&& PHP_CODESNIFFER_INTERACTIVE === false
&& class_exists('PHP_Timer', false) === true
) {
echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
}
return ($report['totals']['errors'] + $report['totals']['warnings']);
}//end generate()
}//end class
?>

View File

@@ -0,0 +1,100 @@
<?php
/**
* Svnblame report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Svnblame report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Svnblame extends PHP_CodeSniffer_Reports_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 = array();
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)
{
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo 'Getting SVN blame info for '.basename($filename).'... ';
}
$command = 'svn blame '.$filename;
$handle = popen($command, 'r');
if ($handle === false) {
echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
exit(2);
}
$rawContent = stream_get_contents($handle);
fclose($handle);
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo 'DONE'.PHP_EOL;
}
$blames = explode("\n", $rawContent);
return $blames;
}//end getBlameContent()
}//end class
?>

View File

@@ -0,0 +1,216 @@
<?php
/**
* Version control report base class for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Version control report base class for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Ben Selby <benmatselby@gmail.com>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.2
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_Reports_VersionControl implements PHP_CodeSniffer_Report
{
/**
* The name of the report we want in the output.
*
* @var string
*/
protected $reportName = 'VERSION CONTROL';
/**
* Prints the author of all errors and warnings, as given by "version control blame".
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param integer $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$authors = array();
$praise = array();
$sources = array();
$width = max($width, 70);
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
$blames = $this->getBlameContent($filename);
foreach ($file['messages'] as $line => $lineErrors) {
$author = $this->getAuthor($blames[($line - 1)]);
if ($author === false) {
continue;
}
if (isset($authors[$author]) === false) {
$authors[$author] = 0;
$praise[$author] = array(
'good' => 0,
'bad' => 0,
);
}
$praise[$author]['bad']++;
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$errorsShown++;
$authors[$author]++;
if ($showSources === true) {
$source = $error['source'];
if (isset($sources[$author][$source]) === false) {
$sources[$author][$source] = 1;
} else {
$sources[$author][$source]++;
}
}
}
}
unset($blames[($line - 1)]);
}//end foreach
// No 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 (false === $author) {
continue;
}
if (isset($authors[$author]) === false) {
// This author doesn't have any errors.
if (PHP_CODESNIFFER_VERBOSITY === 0) {
continue;
}
$authors[$author] = 0;
$praise[$author] = array(
'good' => 0,
'bad' => 0,
);
}
$praise[$author]['good']++;
}//end foreach
}//end foreach
if ($errorsShown === 0) {
// Nothing to show.
return 0;
}
arsort($authors);
echo PHP_EOL.'PHP CODE SNIFFER '.$this->reportName.' BLAME SUMMARY'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL;
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;
}
foreach ($authors as $author => $count) {
if ($praise[$author]['good'] === 0) {
$percent = 0;
} else {
$total = ($praise[$author]['bad'] + $praise[$author]['good']);
$percent = round(($praise[$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;
echo $line.PHP_EOL;
if ($showSources === true && isset($sources[$author]) === true) {
$errors = $sources[$author];
asort($errors);
$errors = array_reverse($errors);
foreach ($errors as $source => $count) {
if ($source === 'count') {
continue;
}
$line = str_repeat(' ', (5 - strlen($count))).$count;
echo ' '.$source.str_repeat(' ', ($width - 14 - strlen($source))).$line.PHP_EOL;
}
}
}//end foreach
echo str_repeat('-', $width).PHP_EOL;
echo 'A TOTAL OF '.$errorsShown.' SNIFF VIOLATION(S) ';
echo 'WERE COMMITTED BY '.count($authors).' AUTHOR(S)'.PHP_EOL;
echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
if ($toScreen === true
&& PHP_CODESNIFFER_INTERACTIVE === false
&& class_exists('PHP_Timer', false) === true
) {
echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
}
return $errorsShown;
}//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
?>

View File

@@ -0,0 +1,107 @@
<?php
/**
* Xml report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Xml report for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Gabriele Santini <gsantini@sqli.com>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2009 SQLI <www.sqli.com>
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Reports_Xml implements PHP_CodeSniffer_Report
{
/**
* Prints all violations for processed files, in a proprietary XML format.
*
* Errors and warnings are displayed together, grouped by file.
*
* @param array $report Prepared report.
* @param boolean $showSources Show sources?
* @param int $width Maximum allowed lne width.
* @param boolean $toScreen Is the report being printed to screen?
*
* @return string
*/
public function generate(
$report,
$showSources=false,
$width=80,
$toScreen=true
) {
$out = new XMLWriter;
$out->openMemory();
$out->setIndent(true);
$out->startDocument('1.0', 'UTF-8');
$out->startElement('phpcs');
$out->writeAttribute('version', '1.3.3');
$errorsShown = 0;
foreach ($report['files'] as $filename => $file) {
if (empty($file['messages']) === true) {
continue;
}
$out->startElement('file');
$out->writeAttribute('name', $filename);
$out->writeAttribute('errors', $file['errors']);
$out->writeAttribute('warnings', $file['warnings']);
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$error['type'] = strtolower($error['type']);
if (PHP_CODESNIFFER_ENCODING !== 'utf-8') {
$error['message'] = iconv(PHP_CODESNIFFER_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->text($error['message']);
$out->endElement();
$errorsShown++;
}
}
}//end foreach
$out->endElement();
}//end foreach
$out->endElement();
echo $out->flush();
return $errorsShown;
}//end generate()
}//end class
?>