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:----K+MpiKI5330G2vSxBQSLLQIK3a0cfSHQQo3zZH6at0IPMzAom4G83u8+/Raj1xGnmScbPnZQ7dwAuyuUBx5atuVc/tZUYJKkGLVw4eJSOjLrijjOcXgA6n5HR1HiFUA7otCCKM2JqdcT2MdvAWS5KlBoaGRQP6a7gehJNiYDGN/t3Yzm4TWHhDLihdgPEbg49n4cLmMfRBJUyy1Hejz+VnAbiH2HVwwRw+iFqEejj9Hd1XeBc9QI+rFwHip1YHdBQti3hb7D6d4VhdjP/TP/YkZn9OOie3ob4B5z41G+fJgsyI1/pIyHepjdd6M7lNvl/CYvdg+82u3WEokZkthXbl8KNAUhs3ws9Gkje0SU/XJZJjy/t+pJcX0c4tRWv3/KV+XOlpBi3dY65FjUnL02YF/wjXTnZYFoK+hySwhtTGzANOGBsz92RJ/DKbxNpfbhMyivAInupMq56kLfFcqp+DqgzZsuB6mrtB2CuHby28N2VwlxFyhFkzsS/KRGxSWkbmD+bW5Rw+p9l9mG0fCa1FU7k3GtnGthFXL37quyfL74eKijl0WjKZbxbw3O/w0Lb2w2vYpah0EuzQpXtkM7RDKNikQztbmTn74uqz8GNpX9qE/hitgR//B7kT/PkQAdSddi9ECo3JjIGx13D1xLgjzafpRf7D2R/Jt4wmzln6o=----ATTACHMENT:----NjgyMDEzNjEwNjMzNzY2NiA5OTE1MjE0MzE1NDIwMTEyIDEyNzY2NzA3OTM3MjU0ODU=