diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index a1855a713b..b3ddcf1d69 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -162,10 +162,14 @@ public function getObjectClassNames(): array public function getObjectClassReflections(): array { - return $this->pickFromTypes( - static fn (Type $type) => $type->getObjectClassReflections(), - static fn (Type $type) => $type->isObject()->yes(), - ); + $reflections = []; + foreach ($this->types as $type) { + foreach ($type->getObjectClassReflections() as $reflection) { + $reflections[] = $reflection; + } + } + + return $reflections; } public function getArrays(): array diff --git a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php index 8a9546216e..78c1b75438 100644 --- a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionClassRuleTest.php @@ -85,11 +85,6 @@ public function testRule(): void 183, 'Learn more at https://phpstan.org/user-guide/discovering-symbols', ], - [ - 'PHPDoc tag @phpstan-require-extends contains unknown class IncompatibleRequireExtends\SomeClass.', - 183, - 'Learn more at https://phpstan.org/user-guide/discovering-symbols', - ], ]); } diff --git a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php index e345685e67..7d94f1ce79 100644 --- a/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/RequireExtendsDefinitionTraitRuleTest.php @@ -55,11 +55,6 @@ public function testRule(): void 192, 'Learn more at https://phpstan.org/user-guide/discovering-symbols', ], - [ - 'PHPDoc tag @phpstan-require-extends contains unknown class IncompatibleRequireExtends\SomeClass.', - 192, - 'Learn more at https://phpstan.org/user-guide/discovering-symbols', - ], ]); } diff --git a/tests/PHPStan/Rules/PhpDoc/SealedDefinitionClassRuleTest.php b/tests/PHPStan/Rules/PhpDoc/SealedDefinitionClassRuleTest.php index 3ec5da8925..f898643dcb 100644 --- a/tests/PHPStan/Rules/PhpDoc/SealedDefinitionClassRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/SealedDefinitionClassRuleTest.php @@ -49,6 +49,11 @@ public function testRule(): void 26, 'Learn more at https://phpstan.org/user-guide/discovering-symbols', ], + [ + 'PHPDoc tag @phpstan-sealed contains unknown class IncompatibleSealed\UnknownClass.', + 46, + 'Learn more at https://phpstan.org/user-guide/discovering-symbols', + ], ]); } diff --git a/tests/PHPStan/Rules/PhpDoc/data/incompatible-sealed.php b/tests/PHPStan/Rules/PhpDoc/data/incompatible-sealed.php index ab1f47ba28..36b5680d23 100644 --- a/tests/PHPStan/Rules/PhpDoc/data/incompatible-sealed.php +++ b/tests/PHPStan/Rules/PhpDoc/data/incompatible-sealed.php @@ -39,3 +39,8 @@ interface ValidInterface {} * @phpstan-sealed SomeInterface */ interface ValidInterface2 {} + +/** + * @phpstan-sealed UnknownClass|SomeClass + */ +class InvalidClassWithUnion {}