diff --git a/src/Printer/CollectorMetadataPrinter.php b/src/Printer/CollectorMetadataPrinter.php index 8233b7d0..26a1e732 100644 --- a/src/Printer/CollectorMetadataPrinter.php +++ b/src/Printer/CollectorMetadataPrinter.php @@ -19,6 +19,7 @@ use PHPStan\Reflection\ExtendedMethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\ClosureType; +use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IntegerRangeType; use PHPStan\Type\IntersectionType; use PHPStan\Type\MixedType; @@ -65,6 +66,10 @@ public function printArgTypesAsString( return ResolvedTypes::UNKNOWN_TYPES; } + if ($argType instanceof GenericObjectType) { + return ResolvedTypes::UNKNOWN_TYPES; + } + if ($argType instanceof PHPStanUnionType) { return ResolvedTypes::UNKNOWN_TYPES; } diff --git a/tests/Rules/NarrowPublicClassMethodParamTypeRule/Fixture/Generics/SkipSameGeneric.php b/tests/Rules/NarrowPublicClassMethodParamTypeRule/Fixture/Generics/SkipSameGeneric.php new file mode 100644 index 00000000..160755ec --- /dev/null +++ b/tests/Rules/NarrowPublicClassMethodParamTypeRule/Fixture/Generics/SkipSameGeneric.php @@ -0,0 +1,19 @@ + $_werbemasse + */ + public function setWerbemasse($_werbemasse): void + { + $this->_werbemasse = $_werbemasse; + } +} + + diff --git a/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php b/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php index ff2044be..182582ca 100644 --- a/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php +++ b/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php @@ -160,6 +160,14 @@ public static function provideData(): Iterator $argErrorMessage = sprintf(NarrowPublicClassMethodParamTypeRule::ERROR_MESSAGE, 'bool'); yield [[__DIR__ . '/Fixture/ExplicitlyNullableParams.php'], [[$argErrorMessage, 9]]]; + + // skip generics + yield [[ + __DIR__ . '/Fixture/Generics/SkipSameGeneric.php', + __DIR__ . '/Source/SkipSameGeneric/MyGroup.php', + __DIR__ . '/Source/SkipSameGeneric/MyIterator.php', + __DIR__ . '/Source/SkipSameGeneric/MyService.php', + ], []]; } /** diff --git a/tests/Rules/NarrowPublicClassMethodParamTypeRule/Source/SkipSameGeneric/MyGroup.php b/tests/Rules/NarrowPublicClassMethodParamTypeRule/Source/SkipSameGeneric/MyGroup.php new file mode 100644 index 00000000..e0e02d70 --- /dev/null +++ b/tests/Rules/NarrowPublicClassMethodParamTypeRule/Source/SkipSameGeneric/MyGroup.php @@ -0,0 +1,10 @@ +articleModel->setWerbemasse($this->fetchCustomizationPositionsByArtidAndSprache()); + } + + /** + * @return MyIterator + */ + public function fetchCustomizationPositionsByArtidAndSprache(int $artid, int $spracheid): MyIterator + { + } + +}