Skip to content

Commit

Permalink
Merge pull request phpmd#1044 from tvbeek/fix_1020-strict-with-CountI…
Browse files Browse the repository at this point in the history
…nLoopExpression-rule

Fix the strict option on applyOnClassMethods.
  • Loading branch information
kylekatarnls committed Oct 30, 2023
2 parents 2a667f9 + c93e65d commit 59fa602
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/php/PHPMD/AbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ abstract class AbstractRule implements Rule
*/
private $report = null;

/**
* Should this rule force the strict mode.
*
* @var boolean
*/
private $strict = false;

/**
* Returns the name for this rule instance.
*
Expand Down Expand Up @@ -378,6 +385,15 @@ public function getStringProperty($name, $default = null)
return (string)$this->getProperty($name, $default);
}

/**
* @param bool $strict
* @return void
*/
public function setStrict($strict)
{
$this->strict = $strict;
}

/**
* This method adds a violation to all reports for this violation type and
* for the given <b>$node</b> instance.
Expand Down Expand Up @@ -409,7 +425,7 @@ protected function addViolation(
protected function applyOnClassMethods(AbstractTypeNode $node)
{
foreach ($node->getMethods() as $method) {
if ($method->hasSuppressWarningsAnnotationFor($this)) {
if (!$this->strict && $method->hasSuppressWarningsAnnotationFor($this)) {
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/php/PHPMD/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ public function apply(AbstractNode $node)
continue;
}
$rule->setReport($this->report);
if (method_exists($rule, 'setStrict')) {
$rule->setStrict($this->strict);
}
$rule->apply($node);
}
}
Expand Down

0 comments on commit 59fa602

Please sign in to comment.