Skip to content

Commit 5cc6484

Browse files
authored
Merge pull request #15 from veewee/copy-xsdtype
Copy xsdtype with new name
2 parents 880d21d + 7a98a33 commit 5cc6484

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Metadata/Model/XsdType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ public static function any(): self
9090
);
9191
}
9292

93+
public static function void(): self
94+
{
95+
return self::guess('void')
96+
->withBaseType('mixed')
97+
->withMeta(
98+
static fn (TypeMeta $meta): TypeMeta => $meta
99+
->withIsSimple(true)
100+
->withIsNil(true)
101+
);
102+
}
103+
93104
/**
94105
* @return array<string, string>
95106
*/
@@ -286,6 +297,14 @@ public function __toString(): string
286297
return $this->name;
287298
}
288299

300+
public function copy(string $name): self
301+
{
302+
$new = clone $this;
303+
$new->name = $name;
304+
305+
return $new;
306+
}
307+
289308
private static function convertBaseType(string $baseType, string $fallback): string
290309
{
291310
return self::fetchAllKnownBaseTypeMappings()[strtolower($baseType)] ?? $fallback;

tests/Unit/Metadata/Model/XsdTypeTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,22 @@ public function test_it_can_return_name_as_string()
137137

138138
static::assertSame('myType', (string) $new);
139139
}
140+
141+
142+
public function test_it_can_copy_a_type(): void
143+
{
144+
$type = XsdType::any();
145+
$new = $type->copy('new');
146+
147+
static::assertSame('new', $new->getName());
148+
static::assertSame($type->getBaseType(), $new->getBaseType());
149+
static::assertSame($type->getMemberTypes(), $new->getMemberTypes());
150+
static::assertSame($type->getXmlNamespace(), $new->getXmlNamespace());
151+
static::assertSame($type->getXmlNamespaceName(), $new->getXmlNamespaceName());
152+
static::assertSame($type->getXmlTargetNamespace(), $new->getXmlTargetNamespace());
153+
static::assertSame($type->getXmlTargetNamespaceName(), $new->getXmlTargetNamespaceName());
154+
static::assertSame($type->getXmlTargetNodeName(), $new->getXmlTargetNodeName());
155+
static::assertSame($type->getXmlTypeName(), $new->getXmlTypeName());
156+
static::assertSame($type->getMeta(), $new->getMeta());
157+
}
140158
}

0 commit comments

Comments
 (0)