Permalink
Browse files

If you create your own PHP_CodeSniffer object, PHPCS will no longer e…

…xit when an unknown argument is found
  • Loading branch information...
gsherwood committed Feb 18, 2013
1 parent 44f1655 commit 3179a841625698d1574de35dcefb4704b0c6b1f6
Showing with 21 additions and 0 deletions.
  1. +1 −0 CodeSniffer.php
  2. +18 −0 CodeSniffer/CLI.php
  3. +2 −0 package.xml
View
@@ -233,6 +233,7 @@ public function __construct(
$this->cli = new PHP_CodeSniffer_CLI();
$this->cli->errorSeverity = PHPCS_DEFAULT_ERROR_SEV;
$this->cli->warningSeverity = PHPCS_DEFAULT_WARN_SEV;
+ $this->cli->dieOnUnknownArg = false;
}//end __construct()
View
@@ -53,6 +53,16 @@ class PHP_CodeSniffer_CLI
*/
public $warningSeverity = 0;
+ /**
+ * Whether or not to kill the process when an unknown command line arg is found.
+ *
+ * If FALSE, arguments that are not command line options or file/directory paths
+ * will be ignored and execution will continue.
+ *
+ * @var bool
+ */
+ public $dieOnUnknownArg = true;
+
/**
* Exits if the minimum requirements of PHP_CodSniffer are not met.
@@ -448,13 +458,21 @@ public function processUnknownArgument($arg, $pos, $values)
{
// We don't know about any additional switches; just files.
if ($arg{0} === '-') {
+ if ($this->dieOnUnknownArg === false) {
+ return $values;
+ }
+
echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
}
$file = realpath($arg);
if (file_exists($file) === false) {
+ if ($this->dieOnUnknownArg === false) {
+ return $values;
+ }
+
echo 'ERROR: The file "'.$arg.'" does not exist.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
View
@@ -29,6 +29,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
- PSR2 SwitchDeclarationSniff now has a setting to specify how many spaces code should be indented
-- Default remains at 4; override the indent setting in a ruleset.xml file to change
-- Thanks to Asher Snyder for the patch
+ - If you create your own PHP_CodeSniffer object, PHPCS will no longer exit when an unknown argument is found
+ -- This allows you to create wrapper scripts for PHPCS more easily
- Fixed bug #19819 : Freeze with syntax error in use statement
- Fixed bug #19820 : Wrong message level in Generic_Sniffs_CodeAnalysis_EmptyStatementSniff
</notes>

1 comment on commit 3179a84

@stronk7

This comment has been minimized.

Show comment Hide comment
@stronk7

stronk7 Feb 18, 2013

Contributor

Aha, looks sensible, thanks! +1

Offtopic, note that we ended using:

define('PHP_CODESNIFFER_IN_TESTS', true);

so then CLI ignores ALL params (perfect for our uses).

while writing our own testing infrastructure, coz we were unable to extend AbstractSniffUnitTest and ended building our own here:

https://github.com/stronk7/moodle-local_codechecker/blob/master/tests/local_codechecker_testcase.php

And here there are some uses (both the number of lines and optionally, contents & source are testable):

https://github.com/stronk7/moodle-local_codechecker/blob/master/moodle/tests/moodlestandard_test.php

it's not 100% automated (based in the names, like AbstractSniffUnitTest, but provides some extra testing functionality).

Ciao, Eloy :-)

Contributor

stronk7 commented on 3179a84 Feb 18, 2013

Aha, looks sensible, thanks! +1

Offtopic, note that we ended using:

define('PHP_CODESNIFFER_IN_TESTS', true);

so then CLI ignores ALL params (perfect for our uses).

while writing our own testing infrastructure, coz we were unable to extend AbstractSniffUnitTest and ended building our own here:

https://github.com/stronk7/moodle-local_codechecker/blob/master/tests/local_codechecker_testcase.php

And here there are some uses (both the number of lines and optionally, contents & source are testable):

https://github.com/stronk7/moodle-local_codechecker/blob/master/moodle/tests/moodlestandard_test.php

it's not 100% automated (based in the names, like AbstractSniffUnitTest, but provides some extra testing functionality).

Ciao, Eloy :-)

Please sign in to comment.