Skip to content

Commit dd304b3

Browse files
committed
bug #48251 [PropertyInfo] ignore const expressions read by phpdocumentor (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] ignore const expressions read by phpdocumentor | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | 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. Commits ------- be5b76a ignore const expressions read by phpdocumentor
2 parents 5882b4f + be5b76a commit dd304b3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyInfo\Util;
1313

14+
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
1415
use phpDocumentor\Reflection\PseudoTypes\List_;
1516
use phpDocumentor\Reflection\Type as DocType;
1617
use phpDocumentor\Reflection\Types\Array_;
@@ -39,6 +40,11 @@ final class PhpDocTypeHelper
3940
*/
4041
public function getTypes(DocType $varType): array
4142
{
43+
if ($varType instanceof ConstExpression) {
44+
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
45+
return [];
46+
}
47+
4248
$types = [];
4349
$nullable = false;
4450

@@ -64,6 +70,11 @@ public function getTypes(DocType $varType): array
6470
for ($typeIndex = 0; $varType->has($typeIndex); ++$typeIndex) {
6571
$type = $varType->get($typeIndex);
6672

73+
if ($type instanceof ConstExpression) {
74+
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
75+
return [];
76+
}
77+
6778
// If null is present, all types are nullable
6879
if ($type instanceof Null_) {
6980
$nullable = true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy