Skip to content

Commit 38b1e3b

Browse files
committed
Fixed the svn pre-commit hook. This required the processFile method to do its own report caching.
1 parent 4d69878 commit 38b1e3b

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CodeSniffer.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,6 @@ public function process($files, $standards, array $restrictions=array(), $local=
466466
$phpcsFile = $this->processFile($file);
467467
$numProcessed++;
468468

469-
// Cache the report data for this file so we can unset it to save memory.
470-
$this->reporting->cacheFileReport($phpcsFile, $cliValues);
471-
472469
if (PHP_CODESNIFFER_VERBOSITY > 0
473470
|| PHP_CODESNIFFER_INTERACTIVE === true
474471
|| $showProgress === false
@@ -1308,7 +1305,11 @@ public function processFile($file, $contents=null)
13081305
$phpcsFile->addError($error, null);
13091306
}//end try
13101307

1308+
$cliValues = $this->cli->getCommandLineValues();
1309+
13111310
if (PHP_CODESNIFFER_INTERACTIVE === false) {
1311+
// Cache the report data for this file so we can unset it to save memory.
1312+
$this->reporting->cacheFileReport($phpcsFile, $cliValues);
13121313
return $phpcsFile;
13131314
}
13141315

@@ -1317,8 +1318,6 @@ public function processFile($file, $contents=null)
13171318
Print the error report for the current file and then wait for user input.
13181319
*/
13191320

1320-
$cliValues = $this->cli->getCommandLineValues();
1321-
13221321
// Get current violations and then clear the list to make sure
13231322
// we only print violations for a single file each time.
13241323
$numErrors = null;

CodeSniffer/Reporting.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public function factory($type)
114114
*/
115115
public function cacheFileReport(PHP_CodeSniffer_File $phpcsFile, array $cliValues)
116116
{
117+
if (isset($cliValues['reports']) === false) {
118+
// This happens during unit testing, or any time someone just wants
119+
// the error data and not the printed report.
120+
return;
121+
}
122+
117123
$reportData = $this->prepareFileReport($phpcsFile);
118124
$errorsShown = false;
119125

scripts/phpcs-svn-pre-commit

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI
107107
$contents = preg_replace('/^.{4}/m', null, $contents);
108108

109109
$values['standard'] = $this->validateStandard($values['standard']);
110-
if (PHP_CodeSniffer::isInstalledStandard($values['standard']) === false) {
111-
// They didn't select a valid coding standard, so help them
112-
// out by letting them know which standards are installed.
113-
echo 'ERROR: the "'.$values['standard'].'" coding standard is not installed. ';
114-
$this->printInstalledStandards();
115-
exit(2);
110+
foreach ($values['standard'] as $standard) {
111+
if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
112+
// They didn't select a valid coding standard, so help them
113+
// out by letting them know which standards are installed.
114+
echo 'ERROR: the "'.$standard.'" coding standard is not installed. ';
115+
$this->printInstalledStandards();
116+
exit(2);
117+
}
116118
}
117119

118120
$phpcs = new PHP_CodeSniffer(

0 commit comments

Comments
 (0)