diff --git a/src/Rules/Variables/ParameterOutAssignedTypeRule.php b/src/Rules/Variables/ParameterOutAssignedTypeRule.php index 9c24597525..02ce19c05e 100644 --- a/src/Rules/Variables/ParameterOutAssignedTypeRule.php +++ b/src/Rules/Variables/ParameterOutAssignedTypeRule.php @@ -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 [ diff --git a/tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php b/tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php index ed68b380b1..34da13d4f8 100644 --- a/tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php +++ b/tests/PHPStan/Rules/Variables/ParameterOutAssignedTypeRuleTest.php @@ -37,6 +37,7 @@ public function testRule(): void [ 'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz() expects list, 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, non-empty-list<\'str\'|int> given.', @@ -45,6 +46,8 @@ public function testRule(): void [ 'Parameter &$p @param-out type of method ParameterOutAssignedType\Foo::doBaz3() expects list>, array, array, int>> given.', 56, + '• array, int> might not be a list.' . "\n" . + '• array, array, int>> might not be a list.', ], [ 'Parameter &$p by-ref type of method ParameterOutAssignedType\Foo::doNoParamOut() expects string, int given.',