Skip to content

Commit

Permalink
Merge pull request #882 from ergebnis/fix/identifier
Browse files Browse the repository at this point in the history
Fix: Return `RuleError` with identifier
  • Loading branch information
localheinz authored Dec 1, 2024
2 parents f72567f + 684e01c commit 449466b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.5.0...main`][2.5.0...main].

### Fixed

- Returned rule with error identifier ([#882]), by [@localheinz]

## [`2.5.0`][2.5.0]

For a full diff see [`2.4.0...2.5.0`][2.4.0...2.5.0].
Expand Down Expand Up @@ -543,6 +547,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
[#877]: https://github.com/ergebnis/phpstan-rules/pull/877
[#878]: https://github.com/ergebnis/phpstan-rules/pull/878
[#880]: https://github.com/ergebnis/phpstan-rules/pull/880
[#882]: https://github.com/ergebnis/phpstan-rules/pull/882

[@enumag]: https://github.com/enumag
[@ergebnis]: https://github.com/ergebnis
Expand Down
8 changes: 5 additions & 3 deletions src/Methods/NoConstructorParameterWithDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ public function processNode(

$className = $classReflection->getName();

return \array_values(\array_map(static function (Node\Param $node) use ($className): string {
return \array_values(\array_map(static function (Node\Param $node) use ($className): Rules\RuleError {
/** @var Node\Expr\Variable $variable */
$variable = $node->var;

/** @var string $parameterName */
$parameterName = $variable->name;

return \sprintf(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf(
'Constructor in %s has parameter $%s with default value.',
$className,
$parameterName,
);
));

return $ruleErrorBuilder->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString())->build();
}, $params));
}
}

0 comments on commit 449466b

Please sign in to comment.