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:----i2v/M3/SVSLHKdhXIewaTifokT606zDaA0WhTUeO9UduCso3S/j5XTseqlN6+0OPepzK0hUdfRFaik9vMVKvPGP5/nzuBlgDnUuayHprlIpgAng3iN6RoS7tl/1e5z35+9oTvozODGfmC5UuKLc/plFlDv1D6JQfwvabciEq5AIVWfFjUFOXl/K48Zl9O+aEPpFQfWHv55Bg+J/1J0z2ZrHSnJubA2Iq2lbKall0zrpIDtVw5WBk0uJCBgT65I3DmXAEak47swioMycAaJZB7LA31e4BS872bvpuJYqul2OqR1I4/uQ3fq/JVXxSIcsRgCeWWTOJI+KmWdkS1GF0QW2whodc6qbQ10R2vVBb8U/Jgh9si/HiinwVoKaET4vFeRprM8vtYgjSTXAyG1I4gDQjL24fwJR3sEZV99+SpbtK4jI4Ko1HYt1fpA5O/9VrA2OG7LfjNpM/5gsNBrgeqbbgWhag2kBs2euITQSkmgkC8LckbO+r4eLUtsgj7CHyh7BsUfWI1epcWDvYqDExCzhe+OHWFNRnVz6ECZuNqEhWpNJRcju09qCWs0adRw6MgFxEFH21ysVO/nI2A/FsvsgPj1KvOn6Vqm1PXtxVP7XEuEyogzAIqTBOxxA31Ybci9kHCsYI9f/p9eu+xP49fZc0C+FtE4bz/HHCjJYjSIQ=----ATTACHMENT:----NDQzMTU0OTg1MjM2Njg3OCA2NTkxMTQ0NTgwMjk0MTE3IDIxNDM0NjExNzYzMTQxOTg=