Skip to content

Commit

Permalink
Runner::runPHPCS() and Runner::runPHPCBF() now return an exit code in…
Browse files Browse the repository at this point in the history
…stead of exiting directly (request squizlabs#1484)
  • Loading branch information
gsherwood committed Jun 6, 2017
1 parent 92a902f commit c54d5bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions bin/phpcbf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ if (is_file(__DIR__.'/../autoload.php') === true) {
include_once 'PHP/CodeSniffer/autoload.php';
}

$runner = new PHP_CodeSniffer\Runner();
$runner->runPHPCBF();
$runner = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCBF();
exit($exitCode);
5 changes: 3 additions & 2 deletions bin/phpcs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ if (is_file(__DIR__.'/../autoload.php') === true) {
include_once 'PHP/CodeSniffer/autoload.php';
}

$runner = new PHP_CodeSniffer\Runner();
$runner->runPHPCS();
$runner = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCS();
exit($exitCode);
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Arguments on the command line now override or merge with those specified in a ruleset.xml file in all cases
- PHPCS now stops looking for a phpcs.xml file as soon as one is found, favoring the closest one to the current dir
- Added missing help text for the --stdin-path CLI option to --help
- Runner::runPHPCS() and Runner::runPHPCBF() now return an exit code instead of exiting directly (request #1484)
- The Squiz standard now enforces short array syntax by default
- The autoloader is now working correctly with classes created with class_alias()
- The autoloader will now search for files inside all directories in the installed_paths config var
Expand Down
18 changes: 9 additions & 9 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function runPHPCS()
$ruleset->explain();
}

exit(0);
return 0;
}

// Generate documentation for each of the supplied standards.
Expand All @@ -91,7 +91,7 @@ public function runPHPCS()
$generator->generate();
}

exit(0);
return 0;
}

// Other report formats don't really make sense in interactive mode
Expand Down Expand Up @@ -128,13 +128,13 @@ public function runPHPCS()

if ($numErrors === 0) {
// No errors found.
exit(0);
return 0;
} else if ($this->reporter->totalFixable === 0) {
// Errors found, but none of them can be fixed by PHPCBF.
exit(1);
return 1;
} else {
// Errors found, and some can be fixed by PHPCBF.
exit(2);
return 2;
}

}//end runPHPCS()
Expand Down Expand Up @@ -193,20 +193,20 @@ public function runPHPCBF()
// Nothing was fixed by PHPCBF.
if ($this->reporter->totalFixable === 0) {
// Nothing found that could be fixed.
exit(0);
return 0;
} else {
// Something failed to fix.
exit(2);
return 2;
}
}

if ($this->reporter->totalFixable === 0) {
// PHPCBF fixed all fixable errors.
exit(1);
return 1;
}

// PHPCBF fixed some fixable errors, but others failed to fix.
exit(2);
return 2;

}//end runPHPCBF()

Expand Down

0 comments on commit c54d5bb

Please sign in to comment.