diff --git a/src/Metadata/Model/XsdType.php b/src/Metadata/Model/XsdType.php index dc6ad46..3b63f0d 100644 --- a/src/Metadata/Model/XsdType.php +++ b/src/Metadata/Model/XsdType.php @@ -90,6 +90,17 @@ public static function any(): self ); } + public static function void(): self + { + return self::guess('void') + ->withBaseType('mixed') + ->withMeta( + static fn (TypeMeta $meta): TypeMeta => $meta + ->withIsSimple(true) + ->withIsNil(true) + ); + } + /** * @return array */ @@ -286,6 +297,14 @@ public function __toString(): string return $this->name; } + public function copy(string $name): self + { + $new = clone $this; + $new->name = $name; + + return $new; + } + private static function convertBaseType(string $baseType, string $fallback): string { return self::fetchAllKnownBaseTypeMappings()[strtolower($baseType)] ?? $fallback; diff --git a/tests/Unit/Metadata/Model/XsdTypeTest.php b/tests/Unit/Metadata/Model/XsdTypeTest.php index bc356cb..c25bd47 100644 --- a/tests/Unit/Metadata/Model/XsdTypeTest.php +++ b/tests/Unit/Metadata/Model/XsdTypeTest.php @@ -137,4 +137,22 @@ public function test_it_can_return_name_as_string() static::assertSame('myType', (string) $new); } + + + public function test_it_can_copy_a_type(): void + { + $type = XsdType::any(); + $new = $type->copy('new'); + + static::assertSame('new', $new->getName()); + static::assertSame($type->getBaseType(), $new->getBaseType()); + static::assertSame($type->getMemberTypes(), $new->getMemberTypes()); + static::assertSame($type->getXmlNamespace(), $new->getXmlNamespace()); + static::assertSame($type->getXmlNamespaceName(), $new->getXmlNamespaceName()); + static::assertSame($type->getXmlTargetNamespace(), $new->getXmlTargetNamespace()); + static::assertSame($type->getXmlTargetNamespaceName(), $new->getXmlTargetNamespaceName()); + static::assertSame($type->getXmlTargetNodeName(), $new->getXmlTargetNodeName()); + static::assertSame($type->getXmlTypeName(), $new->getXmlTypeName()); + static::assertSame($type->getMeta(), $new->getMeta()); + } }