diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index db25e14f44736..d00b81e5f17d0 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -227,7 +227,11 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $constructor = new \ReflectionMethod($class, '__construct'); $rawDocNode = $constructor->getDocComment(); $source = self::MUTATOR; - } elseif (null === $rawDocNode = $reflectionProperty->getDocComment() ?: null) { + } else { + $rawDocNode = $reflectionProperty->getDocComment(); + } + + if (!$rawDocNode) { return null; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 0cf346fce03c1..9edea0725481a 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -18,6 +18,7 @@ use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy; +use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem; use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait; use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait; @@ -439,15 +440,16 @@ public function testDummyNamespaceWithProperty() /** * @dataProvider php80TypesProvider */ - public function testExtractPhp80Type($property, array $type = null) + public function testExtractPhp80Type(string $class, $property, array $type = null) { - $this->assertEquals($type, $this->extractor->getTypes(Php80Dummy::class, $property, [])); + $this->assertEquals($type, $this->extractor->getTypes($class, $property, [])); } public function php80TypesProvider() { return [ - ['promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80Dummy::class, 'promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80PromotedDummy::class, 'promoted', null], ]; } } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php new file mode 100644 index 0000000000000..f612df99e2ba4 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\Tests\Fixtures; + +class Php80PromotedDummy +{ + public function __construct(private string $promoted) + { + } + + public function getPromoted(): string + { + return $this->promoted; + } +}