Repository: symfony/symfony
File: src/Symfony/Component/TypeInfo/Type/CollectionType.php (PHP)

Code before:
        private readonly BuiltinType|ObjectType|GenericType $type,
        private readonly bool $isList = false,
    ) {
        if ($type instanceof BuiltinType && TypeIdentifier::ARRAY !== $type->getTypeIdentifier() && TypeIdentifier::ITERABLE !== $type->getTypeIdentifier()) {
            throw new InvalidArgumentException(\sprintf('Cannot create "%s" with "%s" type.', self::class, $type));
        }

        if ($this->isList()) {
            if (!$type->isIdentifiedBy(TypeIdentifier::ARRAY)) {
                trigger_deprecation('symfony/type-info', '7.3', 'Creating a "%s" that is a list and not an array is deprecated and will throw a "%s" in 8.0.', self::class, InvalidArgumentException::class);
                // throw new InvalidArgumentException(\sprintf('Cannot create a "%s" as list when type is not "array".', self::class));
            }

            $keyType = $this->getCollectionKeyType();

            if (!$keyType instanceof BuiltinType || TypeIdentifier::INT !== $keyType->getTypeIdentifier()) {
                throw new InvalidArgumentException(\sprintf('"%s" is not a valid list key type.', (string) $keyType));
            }
        } else {
            $keyType = $this->getCollectionKeyType();

            if ($keyType instanceof UnionType) {
                $types = $keyType->getTypes();
            } else {
                $types = [$keyType];
            }

            foreach ($types as $type) {
                if ($type instanceof BuiltinType && !\in_array($type->getTypeIdentifier(), [TypeIdentifier::INT, TypeIdentifier::STRING], true)) {
                    throw new InvalidArgumentException(\sprintf('"%s" is not a valid array key type.', (string) $keyType));
                }
            }
        }
    }

    /**
     * @param array<Type> $types
     */
    public static function mergeCollectionValueTypes(array $types): Type
    {
        if (!$types) {
            throw new InvalidArgumentException('The $types cannot be empty.');
        }

        $normalizedTypes = [];
        $boolTypes = [];
        $objectTypes = [];

        foreach ($types as $type) {
            foreach (($type instanceof UnionType ? $type->getTypes() : [$type]) as $t) {
                // cannot create an union with a standalone type

Review comment (suggestion):
```suggestion
            $keyTypes = $keyType instanceof UnionType ? $keyType->getTypes() : [$keyType];
```

Code after:
        private readonly BuiltinType|ObjectType|GenericType $type,
        private readonly bool $isList = false,
    ) {
        if ($type instanceof BuiltinType && TypeIdentifier::ARRAY !== $type->getTypeIdentifier() && TypeIdentifier::ITERABLE !== $type->getTypeIdentifier()) {
            throw new InvalidArgumentException(\sprintf('Cannot create "%s" with "%s" type.', self::class, $type));
        }

        if ($this->isList()) {
            if (!$type->isIdentifiedBy(TypeIdentifier::ARRAY)) {
                trigger_deprecation('symfony/type-info', '7.3', 'Creating a "%s" that is a list and not an array is deprecated and will throw a "%s" in 8.0.', self::class, InvalidArgumentException::class);
                // throw new InvalidArgumentException(\sprintf('Cannot create a "%s" as list when type is not "array".', self::class));
            }

            $keyType = $this->getCollectionKeyType();

            if (!$keyType instanceof BuiltinType || TypeIdentifier::INT !== $keyType->getTypeIdentifier()) {
                throw new InvalidArgumentException(\sprintf('"%s" is not a valid list key type.', (string) $keyType));
            }
        } elseif ($type instanceof GenericType && $type->getWrappedType() instanceof BuiltinType && TypeIdentifier::ARRAY === $type->getWrappedType()->getTypeIdentifier()) {
            $keyType = $this->getCollectionKeyType();

            $keyTypes = $keyType instanceof UnionType ? $keyType->getTypes() : [$keyType];

            foreach ($keyTypes as $type) {
                if (!$type instanceof BuiltinType || !\in_array($type->getTypeIdentifier(), [TypeIdentifier::INT, TypeIdentifier::STRING], true)) {
                    throw new InvalidArgumentException(\sprintf('"%s" is not a valid array key type.', (string) $keyType));
                }
            }
        }
    }

    /**
     * @param array<Type> $types
     */
    public static function mergeCollectionValueTypes(array $types): Type
    {
        if (!$types) {
            throw new InvalidArgumentException('The $types cannot be empty.');
        }

        $normalizedTypes = [];
        $boolTypes = [];
        $objectTypes = [];

        foreach ($types as $type) {
            foreach (($type instanceof UnionType ? $type->getTypes() : [$type]) as $t) {
                // cannot create an union with a standalone type
                if ($t->isIdentifiedBy(TypeIdentifier::MIXED)) {
                    return Type::mixed();
                }