From be5b76abcd5ee351528e3317c4357250f97e7607 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 19 Nov 2022 18:35:30 +0100 Subject: [PATCH] ignore const expressions read by phpdocumentor With the upcoming release, phpdocumentator will use the PhpStan docblock parser to extract type information. This change ensure that constant expressions are ignored when extracting types (as we did before when phpdocumentor failed to extract the type) as we do not evaluate them inside the PhpDocExtractor. --- .../Component/PropertyInfo/Util/PhpDocTypeHelper.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php b/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php index cafbaaf231b52..c4a2edb174900 100644 --- a/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php +++ b/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php @@ -11,6 +11,7 @@ namespace Symfony\Component\PropertyInfo\Util; +use phpDocumentor\Reflection\PseudoTypes\ConstExpression; use phpDocumentor\Reflection\PseudoTypes\List_; use phpDocumentor\Reflection\Type as DocType; use phpDocumentor\Reflection\Types\Array_; @@ -39,6 +40,11 @@ final class PhpDocTypeHelper */ public function getTypes(DocType $varType): array { + if ($varType instanceof ConstExpression) { + // It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment + return []; + } + $types = []; $nullable = false; @@ -64,6 +70,11 @@ public function getTypes(DocType $varType): array for ($typeIndex = 0; $varType->has($typeIndex); ++$typeIndex) { $type = $varType->get($typeIndex); + if ($type instanceof ConstExpression) { + // It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment + return []; + } + // If null is present, all types are nullable if ($type instanceof Null_) { $nullable = true;