From 1605b57c071638c687a5eb7704a55a984b45427e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Thu, 2 Jun 2022 00:18:04 +0200 Subject: [PATCH 1/2] [PropertyInfo] Add failing test case for multi phpdoc covered promoted properties This demonstrates that https://github.com/symfony/symfony/pull/46056 causes a regression and incorrectly detects types in case there are multiple phpdoc covered promoted properties. --- .../{PhpStanExtractorTestDoc.php => PhpStanExtractorTest.php} | 1 + .../Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) rename src/Symfony/Component/PropertyInfo/Tests/Extractor/{PhpStanExtractorTestDoc.php => PhpStanExtractorTest.php} (99%) diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php similarity index 99% rename from src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php rename to src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 7565994ee0c8c..9b49e70e202a7 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -467,6 +467,7 @@ public function php80TypesProvider() return [ [Php80Dummy::class, 'promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], [Php80Dummy::class, 'promoted', null], + [Php80Dummy::class, 'collection', [new Type(Type::BUILTIN_TYPE_ARRAY, collection: true, collectionValueType: new Type(Type::BUILTIN_TYPE_STRING))]], [Php80PromotedDummy::class, 'promoted', null], ]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php index e7ae2fc83bfec..dc985fea0b212 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php @@ -17,8 +17,9 @@ class Php80Dummy /** * @param string $promotedAndMutated + * @param array $collection */ - public function __construct(private mixed $promoted, private mixed $promotedAndMutated) + public function __construct(private mixed $promoted, private mixed $promotedAndMutated, private array $collection) { } From f503e37d29e99de2f52203dff4cf4ea4ebb5201c Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Tue, 7 Jun 2022 11:36:55 +0300 Subject: [PATCH 2/2] [PropertyInfo] Fix multi phpdoc covered promoted properties --- .../PropertyInfo/Extractor/PhpStanExtractor.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index 52a4a78f2537f..429f43202543d 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -99,6 +99,14 @@ public function getTypes(string $class, string $property, array $context = []): continue; } + if ( + $tagDocNode->value instanceof ParamTagValueNode + && null === $prefix + && $tagDocNode->value->parameterName !== '$'.$property + ) { + continue; + } + foreach ($this->phpStanTypeHelper->getTypes($tagDocNode->value, $nameScope) as $type) { switch ($type->getClassName()) { case 'self': @@ -239,10 +247,6 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $phpDocNode = $this->phpDocParser->parse($tokens); $tokens->consumeTokenType(Lexer::TOKEN_END); - if (self::MUTATOR === $source && !$this->filterDocBlockParams($phpDocNode, $property)) { - return null; - } - return [$phpDocNode, $source, $reflectionProperty->class]; }