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:----T4fu+h91ZMq8PIbCTA4AzjiwlwK5iF7/Zm90Sv/Li/4jkrRevCayA7m5t6xn5WLYgJI28vOwXPeg/W0/PVbtXV9GbMoX9tL7A2shW45jcirz3RdhRp8ym+HIvQ6TpENMD5qZnPwiRgeKLQ6sYLhjpkOMbvl8qxFQKBHZ2ijGP/GXTEkgh6FJncQN+sOXst6Lx/Ln/LADm/lUdNEDPi73qpuS2spSHnX0oT1uo9w+w2VUl2IbiM0sHTH2yC2SC0XT9TSXUbZeKjXcKgycsBxoIv6osxtnUWJepy7ZDj1whMedb2tEY4aob3pP/R3NHmqVi+LMbNVDx9XlD/TYzJi5QpDBrtFUDU4arqlwz3DSNCdmWpKxvARPeRmijwKQUpv4Yp3p86kbHFWPWeyyy0rZnAx0r8uMTibbkv+v4IfzX7ImsCsu4bfwoFYCH/frri9NuMjaP7uAp/T2n0EtnYdobqLNXm93xXqQah5flMXyZj4P+idb0d42CVpG6yCwfaTftB/F20sAAxEfQBaR07UZ7wb86R0aqwEBNHhOBilGQTbhgQgIPaujhJBwscU2+OAwID8dj84g2xESaFNn+cdn9rvrK5NogY6SejdUtI30mqwTHZe2eZsb1C29WxthRHLDPvHcJpbZ4/rWg1FRAquvmSXOcdU2tlgjnRJedCuFlTA=----ATTACHMENT:----Mjc1MTc0OTg4ODQ0MDc1MCA5MjA2NjUyMTE4Mjc0NDYyIDU0MjIyODExNTQxNzIzMjQ=