Skip to content

Commit

Permalink
Merge pull request #15 from veewee/copy-xsdtype
Browse files Browse the repository at this point in the history
Copy xsdtype with new name
  • Loading branch information
veewee authored Jun 11, 2024
2 parents 880d21d + 7a98a33 commit 5cc6484
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Metadata/Model/XsdType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
*/
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/Metadata/Model/XsdTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 5cc6484

Please sign in to comment.