8000 [PropertyInfo] ignore const expressions read by phpdocumentor by xabbuh · Pull Request #48251 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
xabbuh committed Nov 19, 2022
commit be5b76abcd5ee351528e3317c4357250f97e7607
11 changes: 11 additions & 0 deletions src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
0