Repository: symfony/symfony
File: src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php (PHP)

Code before:
    /**
     * Creates a {@see LegacyType} from a PHPDoc type.
     */
    private function createLegacyType(DocType $type, bool $nullable): ?LegacyType
    {
        $docType = (string) $type;

        if ('mixed[]' === $docType) {
            $docType = 'array';
        } elseif ('array' !== $docType && $type instanceof Array_ && null === $type->getOriginalKeyType()) {
            $docType = \sprintf('%s[]', $type->getValueType());
        }

        if ($type instanceof Collection || $type instanceof Generic) {
            $fqsen = $type->getFqsen();
            if ($type instanceof Collection && $fqsen && 'list' === $fqsen->getName() && !class_exists(List_::class, false) && !class_exists((string) $fqsen)) {
                // Workaround for phpdocumentor/type-resolver < 1.6
                return new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, $nullable, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $this->getTypes($type->getValueType()));
            }

            [$phpType, $class] = $this->getPhpTypeAndClass((string) $fqsen);

            $collection = is_a($class, \Traversable::class, true) || is_a($class, \ArrayAccess::class, true);

            // it's safer to fall back to other extractors if the generic type is too abstract
            if (!$collection && !class_exists($class) && !interface_exists($class)) {
                return null;
            }

            if ($type instanceof Generic) {
                $genericTypes = $type->getTypes();

                if (null === $valueType = $genericTypes[1] ?? null) {
                    $keyType = new Compound([new String_(), new Integer()]);
                    $valueType = $genericTypes[0] ?? new Mixed_();
                } else {
                    $keyType = $genericTypes[0];
                }
            } else {
                $keyType = $type->getKeyType();
                $valueType = $type->getValueType();
            }

            $keys = $this->getTypes($keyType);
            $values = $this->getTypes($valueType);

            return new LegacyType($phpType, $nullable, $class, $collection, $keys, $values);
        }

        // Cannot guess
        if (!$docType || 'mixed' === $docType) {

Review comment (suggestion):
```suggestion
            if (!$collection && !class_exists($class, false) && !interface_exists($class, false)) {
```

Code after:
    /**
     * Creates a {@see LegacyType} from a PHPDoc type.
     */
    private function createLegacyType(DocType $type, bool $nullable): ?LegacyType
    {
        $docType = (string) $type;

        if ('mixed[]' === $docType) {
            $docType = 'array';
        } elseif ('array' !== $docType && $type instanceof Array_ && $this->hasNoExplicitKeyType($type)) {
            $docType = \sprintf('%s[]', $type->getValueType());
        }

        if ($type instanceof Collection || $type instanceof Generic) {
            $fqsen = $type->getFqsen();
            if ($type instanceof Collection && $fqsen && 'list' === $fqsen->getName() && !class_exists(List_::class, false) && !class_exists((string) $fqsen)) {
                // Workaround for phpdocumentor/type-resolver < 1.6
                return new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, $nullable, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $this->getTypes($type->getValueType()));
            }

            [$phpType, $class] = $this->getPhpTypeAndClass((string) $fqsen);

            $collection = is_a($class, \Traversable::class, true) || is_a($class, \ArrayAccess::class, true);

            // it's safer to fall back to other extractors if the generic type is too abstract
            if (!$collection && !class_exists($class, false) && !interface_exists($class, false)) {
                return null;
            }

            if ($type instanceof Generic) {
                $genericTypes = $type->getTypes();

                if (null === $valueType = $genericTypes[1] ?? null) {
                    $keyType = new Compound([new String_(), new Integer()]);
                    $valueType = $genericTypes[0] ?? new Mixed_();
                } else {
                    $keyType = $genericTypes[0];
                }
            } else {
                $keyType = $type->getKeyType();
                $valueType = $type->getValueType();
            }

            $keys = $this->getTypes($keyType);
            $values = $this->getTypes($valueType);

            return new LegacyType($phpType, $nullable, $class, $collection, $keys, $values);
        }

        // Cannot guess
        if (!$docType || 'mixed' === $docType) {