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:----YPExsxrUn/EWRJFcybtj2pY2nMzKx/iPclk+jUlZWKlFeA3+59uN1VAEdRzuqFA0mT+KflTkj4//ZSjvHs7Xk+WAq1TgBB/zcopJdZ8xJdem//QDY5R0Rkhp8Rd7MM1HQSm3Mik3L4ju+gjTvl5hDOVpuHnEicv2pmKU1rNUmK6rLROxW5sdbN42FrrNpcaYTEfyJ5gOEXSYPkqIb3vnwlF5NUQOhRl/MRyqsOIQMPGUCr7pgxma4yEEw8hGWGm58VoEFk2ptzS7Pn4PzT/KiL0Y1K7cokX0XWeEOv96SolkKmgge/ldS1WXftf/3bHkY2K6JPHC57NEfZiUlVU2OURR1TCiQbPnCJ8CK5lKMKZVm+5rWgbeflko/KZIRg7iOisqGSvLYTB3seROZ9ylGJQUJrncqQS/stLdLpQIcyQUsQrbwkkrr4wF2y8GmAjwhxmyomzFZsyuLfiY79SvaJdQif3WJBnWxgNNww713Ml0mKpvk4ZFQYD79Kl5d08QqaBRrht1iBOEKmxcop1eW+ojEawqtoAed4LTUogng9iWGFL3KkkvsHHOtBVO0cTNiRF+Iir37Nrjl7qnommckiIhi4tA+TcTluSq409vjUaGXFH0S2bsEYZ/7ZtASKB1eAhrEVjUhkhzNwDgq2QBkZ1FQ36okPXWTm9Jpt3fr5Y=----ATTACHMENT:----NTU1MTU4NTM3MTU3MjA3OSAxOTgzNjY1OTA0NDExNDM0IDMxOTgyNTQyOTY1ODU2NzQ=