forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By default, phpcbf will replace files using the patch command. A coup…
…le of vars can be changed in the script to now replace the file using PHP or output a new copy of the file using a filename suffix. When not using the patch command, a new report type is used: Cbf. This report cannot be selected from the command line and is only used to update file content when running with phpcbf.
- Loading branch information
Showing
3 changed files
with
168 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?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. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
* @link http://pear.php.net/package/PHP_CodeSniffer | ||
*/ | ||
|
||
/** | ||
* 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. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer | ||
* @author Greg Sherwood <[email protected]> | ||
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
* @version Release: @package_version@ | ||
* @link http://pear.php.net/package/PHP_CodeSniffer | ||
*/ | ||
class PHP_CodeSniffer_Reports_Cbf implements PHP_CodeSniffer_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 boolean $showSources Show sources? | ||
* @param int $width Maximum allowed line width. | ||
* | ||
* @return boolean | ||
*/ | ||
public function generateFileReport( | ||
$report, | ||
PHP_CodeSniffer_File $phpcsFile, | ||
$showSources=false, | ||
$width=80 | ||
) { | ||
ob_start(); | ||
$diff = $phpcsFile->phpcs->reporting->factory('diff'); | ||
$changed = $diff->generateFileReport($report, $phpcsFile); | ||
ob_end_clean(); | ||
|
||
if ($changed === true) { | ||
$cliValues = $phpcsFile->phpcs->cli->getCommandLineValues(); | ||
$newFilename = $report['filename'].$cliValues['phpcbf-suffix']; | ||
$newContent = $phpcsFile->fixer->getContents(); | ||
file_put_contents($newFilename, $newContent); | ||
|
||
echo 'Fixed '.$report['fixable'].' sniff violations in '.$report['filename'].PHP_EOL; | ||
if ($newFilename === $report['filename']) { | ||
echo "\t=> file was overwritten".PHP_EOL; | ||
} else { | ||
echo "\t=> fixed file written to ".basename($newFilename).PHP_EOL; | ||
} | ||
} | ||
|
||
return $changed; | ||
|
||
}//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 boolean $showSources Show sources? | ||
* @param int $width Maximum allowed line width. | ||
* @param boolean $toScreen Is the report being printed to screen? | ||
* | ||
* @return void | ||
*/ | ||
public function generate( | ||
$cachedData, | ||
$totalFiles, | ||
$totalErrors, | ||
$totalWarnings, | ||
$totalFixable, | ||
$showSources=false, | ||
$width=80, | ||
$toScreen=true | ||
) { | ||
echo $cachedData; | ||
echo "Fixed $totalFiles files".PHP_EOL; | ||
|
||
}//end generate() | ||
|
||
|
||
}//end class | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters