@@ -693,6 +693,20 @@ public function getOffsetValueType(Type $offsetType): Type
693693
694694 public function setOffsetValueType (?Type $ offsetType , Type $ valueType , bool $ unionValues = true ): Type
695695 {
696+ if ($ offsetType !== null ) {
697+ $ constantScalars = $ offsetType ->getConstantScalarTypes ();
698+ $ constantScalarsCount = count ($ constantScalars );
699+ if ($ constantScalarsCount > 1 && $ constantScalarsCount < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT ) {
700+ $ arrays = [];
701+ foreach ($ constantScalars as $ constantScalar ) {
702+ $ builder = ConstantArrayTypeBuilder::createFromConstantArray ($ this );
703+ $ builder ->setOffsetValueType ($ constantScalar , $ valueType );
704+ $ arrays [] = $ builder ->getArray ();
705+ }
706+
707+ return TypeCombinator::union ($ this , ...$ arrays );
708+ }
709+ }
696710 $ builder = ConstantArrayTypeBuilder::createFromConstantArray ($ this );
697711 $ builder ->setOffsetValueType ($ offsetType , $ valueType );
698712
@@ -701,6 +715,19 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $uni
701715
702716 public function setExistingOffsetValueType (Type $ offsetType , Type $ valueType ): Type
703717 {
718+ $ constantScalars = $ offsetType ->getConstantScalarTypes ();
719+ $ constantScalarsCount = count ($ constantScalars );
720+ if ($ constantScalarsCount > 1 && $ constantScalarsCount < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT ) {
721+ $ arrays = [];
722+ foreach ($ constantScalars as $ constantScalar ) {
723+ $ builder = ConstantArrayTypeBuilder::createFromConstantArray ($ this );
724+ $ builder ->setOffsetValueType ($ constantScalar , $ valueType );
725+ $ arrays [] = $ builder ->getArray ();
726+ }
727+
728+ return TypeCombinator::union (...$ arrays );
729+ }
730+
704731 $ builder = ConstantArrayTypeBuilder::createFromConstantArray ($ this );
705732 $ builder ->setOffsetValueType ($ offsetType , $ valueType );
706733
0 commit comments