Skip to content

Commit

Permalink
Add extended reasons tips to param out errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thg2k committed Jul 23, 2024
1 parent 4a0ffab commit 3cdae2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Rules/Variables/ParameterOutAssignedTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ public function processNode(Node $node, Scope $scope): array
$functionDescription,
$outType->describe($verbosityLevel),
$assignedExprType->describe($verbosityLevel),
))->identifier(sprintf('%s.type', $isParamOutType ? 'paramOut' : 'parameterByRef'));
))->identifier($isParamOutType ? 'paramOut.type' : 'parameterByRef.type');

$accepts = $outType->acceptsWithReason($assignedExprType, true);
if (!$accepts->result->yes()) {
$errorBuilder->acceptsReasonsTip($accepts->reasons);
}

if (!$isParamOutType) {
$errorBuilder->tip('You can change the parameter out type with @param-out PHPDoc tag.');
$errorBuilder->addTip('You can change the parameter out type with @param-out PHPDoc tag.');
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testRule(): void
[
'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz() expects list<int>, array<0|int<2, max>, int> given.',
38,
'array<0|int<2, max>, int> might not be a list.',
],
[
'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz2() expects list<int>, non-empty-list<\'str\'|int> given.',
Expand All @@ -45,6 +46,8 @@ public function testRule(): void
[
'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz3() expects list<list<int>>, array<int<0, max>, array<int<0, max>, int>> given.',
56,
'• array<int<0, max>, int> might not be a list.' . "\n" .
'• array<int<0, max>, array<int<0, max>, int>> might not be a list.',
],
[
'Parameter &$p by-ref type of method ParameterOutAssignedType\Foo::doNoParamOut() expects string, int given.',
Expand Down

0 comments on commit 3cdae2c

Please sign in to comment.