Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI IgnoreViolationsOnExit option flag #380

Merged
merged 3 commits into from Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/php/PHPMD/TextUI/Command.php
Expand Up @@ -129,7 +129,7 @@ public function run(CommandLineOptions $opts, RuleSetFactory $ruleSetFactory)
$ruleSetFactory
);

if ($phpmd->hasViolations()) {
if ($phpmd->hasViolations() && !$opts->hasIgnoreExitViolations()) {
return self::EXIT_VIOLATION;
}
return self::EXIT_SUCCESS;
Expand Down
24 changes: 23 additions & 1 deletion src/main/php/PHPMD/TextUI/CommandLineOptions.php
Expand Up @@ -139,6 +139,13 @@ class CommandLineOptions
*/
protected $strict = false;

/**
* Should PHPMD exit without error code even if violation is found?
*
* @var boolean
*/
protected $ignoreExitViolations = false;

/**
* List of available rule-sets.
*
Expand Down Expand Up @@ -193,6 +200,9 @@ public function __construct(array $args, array $availableRuleSets = array())
case '--strict':
$this->strict = true;
break;
case '--ignore-exit-violations':
$this->ignoreExitViolations = true;
break;
case (preg_match('(^\-\-reportfile\-(xml|html|text)$)', $arg, $match) > 0):
$this->reportFiles[$match[1]] = array_shift($args);
break;
Expand Down Expand Up @@ -327,6 +337,16 @@ public function hasStrict()
return $this->strict;
}

/**
* Was the <b>--ignore-exit-violations</b> passed to PHPMD's command line interface?
*
* @return boolean
*/
public function hasIgnoreExitViolations()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to ignoreExitViolations().
Haven't looked into it, but does it need to be public?
If not, please use protected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is used in src/main/php/PHPMD/TextUI/Command.php:132

{
return $this->ignoreExitViolations;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to ignoreViolationsOnExit please.

}

/**
* Creates a report renderer instance based on the user's command line
* argument.
Expand Down Expand Up @@ -438,7 +458,9 @@ public function usage()
'--exclude: comma-separated string of patterns that are used to ' .
'ignore directories' . \PHP_EOL .
'--strict: also report those nodes with a @SuppressWarnings ' .
'annotation' . \PHP_EOL;
'annotation' . \PHP_EOL .
'--ignore-exit-violations: will exit with 0 even if a ' .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--ignore-violations-on-exit: will exit with a zero code, even if any violations are found

'violation is found ' . \PHP_EOL;
}

/**
Expand Down