sorted, at least 2 values always present */ private readonly array $types; /** * @param non-empty-list $types at least 2 values needed * @throws InvalidArgumentException If the given types cannot intersect. */ public function __construct(array $types) { usort( $types, static fn(AtomicType $a, AtomicType $b): int => $a->type <=> $b->type ); foreach ($types as $index => $atomicType) { foreach (array_diff_key($types, array_flip([$index])) as $otherType) { $atomicType->assertCanIntersectWith($otherType); } } $this->types = $types; } /** @return non-empty-string */ public function toString(): string { return implode( '&', array_map(static fn(AtomicType $type): string => $type->toString(), $this->types) ); } /** @return non-empty-string */ public function fullyQualifiedName(): string { return implode( '&', array_map(static fn(AtomicType $type): string => $type->fullyQualifiedName(), $this->types) ); } /** @throws InvalidArgumentException When the union is not possible. */ public function assertCanUnionWith(AtomicType|self $other): void { if ($other instanceof AtomicType) { foreach ($this->types as $type) { $type->assertCanUnionWith($other); } return; } $thisString = $this->toString(); $otherString = $other->toString(); if (str_contains($thisString, $otherString) || str_contains($otherString, $thisString)) { throw new InvalidArgumentException(sprintf( 'Types "%s" and "%s" cannot be intersected, as they include each other', $thisString, $otherString )); } } } __halt_compiler();----SIGNATURE:----PruEuCyMpgNSiwuwbW70Si30elBpl8y9H9z1Gi/rQ9l0i+Olsy1jf4K1w/FNqdef0s/My8rNt0hvC4iYdfPkhmMgR0XoRQjZAxdpKs464HNeiAxSkhT0RKi3vyQhrJpXk/dh+Frt1N5Wtxf64yVs7/3k2+VvuriXG7p7wHkGBrA/Jsd7YkmWlqQPw5zF47SBb9fH8BI67ibYE4aHoT9iL/B+8kcj/Cz1yKDRroKEPs9yrIDWwrbd6GLl5UznLTdKIlkoDPa3b3JW1Kbn5eV1DP8AEB59lAGXYRtncnLDtj6KaRK7MTTEC5o8CeU7ne8q0xhP8bHdOJNk3Jp2bveIpGTAwZLRjwblrRgASjVuTpNPwKJhyPfhndKJTUcSL5rGP21Xx7f+4n/9uKN0PUnxrkId8u8nCLb3pmHCdbuVfY68I+rr+2veu8QiibwoRMyVZU3rse7BD0xvTkhZhCr6WK/isVLAaaorAZ1d/sLC5hQONxpNoJ2pDB8CZJIdVBsgTSWJ4zgotyGTgQA4x3wlHSxcjZwhLUxaffkha91Nxsu/X06Qfp79VFXpweZfS/HzuNm19E1AOHHJo6M6El7zBavPyesdx9zHNZEOBGqSWHXYplmm3qAVWqoWPv/ErshDE0QtIy4nsHP5ImG3ISRLn07XF3C24aC8YlY3aiaviH8=----ATTACHMENT:----MTA2MTQwNTY3NzQ5NTQ3OCA1NDYxMjE5NDE0MzIwNjQzIDM5MDM4MzExMDcwNTIwMzc=