diff --git a/src/Rules/NarrowPrivateClassMethodParamTypeRule.php b/src/Rules/NarrowPrivateClassMethodParamTypeRule.php index f81cacc2..2c5baf84 100644 --- a/src/Rules/NarrowPrivateClassMethodParamTypeRule.php +++ b/src/Rules/NarrowPrivateClassMethodParamTypeRule.php @@ -17,6 +17,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleError; use PHPStan\Rules\RuleErrorBuilder; +use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\IntersectionType; use PHPStan\Type\MixedType; @@ -149,7 +150,7 @@ private function validateParam(Param $param, int $position, Expr $expr, Scope $s return null; } - if ($argType instanceof IntersectionType) { + if ($argType instanceof IntersectionType || $argType instanceof GenericObjectType) { return null; } diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipSameGeneric.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipSameGeneric.php new file mode 100644 index 00000000..23b8b237 --- /dev/null +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipSameGeneric.php @@ -0,0 +1,34 @@ +getPricesForArticle(); + $this->getAmounts($prices); + } + + /** + * @param MyIterator $prices + */ + private function getAmounts(MyIterator $prices): void + { + } + + /** + * @return MyIterator + */ + private function getPricesForArticle(): MyIterator + { + /** @var MyIterator */ + return new MyIterator(); + } + +} diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php index 84483443..f5a05e80 100644 --- a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php @@ -51,6 +51,7 @@ public static function provideData(): Iterator yield [__DIR__ . '/Fixture/SkipGenericType.php', []]; yield [__DIR__ . '/Fixture/SkipAbstractBase.php', []]; yield [__DIR__ . '/Fixture/SkipVariadics.php', []]; + yield [__DIR__ . '/Fixture/SkipSameGeneric.php', []]; } /** diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Source/MyIterator.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Source/MyIterator.php new file mode 100644 index 00000000..ca5c1423 --- /dev/null +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Source/MyIterator.php @@ -0,0 +1,12 @@ +