Skip to content

Commit

Permalink
fixes goetas-webservices#168 : add choice-in-sequence handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmans-check authored and BigBadBassMan committed Nov 15, 2024
1 parent 2b91509 commit 3f5d4fe
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/Php/PhpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(NamingStrategy $namingStrategy, LoggerInterface $log

private $classes = [];

public function convert(array $schemas)
public function convert(array $schemas): array
{
$visited = [];
$this->classes = [];
Expand All @@ -69,7 +69,7 @@ public function convert(array $schemas)
/**
* @return PHPClass[]
*/
private function getTypes()
private function getTypes(): array
{
uasort($this->classes, function ($a, $b) {
return strcmp($a['class']->getFullName(), $b['class']->getFullName());
Expand All @@ -84,7 +84,7 @@ private function getTypes()
return $ret;
}

private function navigate(Schema $schema, array &$visited)
private function navigate(Schema $schema, array &$visited): void
{
if (isset($visited[spl_object_hash($schema)])) {
return;
Expand All @@ -105,7 +105,7 @@ private function navigate(Schema $schema, array &$visited)
}
}

private function visitTypeBase(PHPClass $class, Type $type)
private function visitTypeBase(PHPClass $class, Type $type): void
{
$class->setAbstract($type->isAbstract());

Expand All @@ -119,34 +119,36 @@ private function visitTypeBase(PHPClass $class, Type $type)
$this->visitComplexType($class, $type);
}
}

/**
* Process xsd:complexType xsd:sequence xsd:element
*
* @param PHPClass $class
* @param Schema $schema
* @param Sequence $sequence
*/
private function visitSequence(PHPClass $class, Schema $schema, Sequence $sequence)
{
private function visitSequence(PHPClass $class, Schema $schema, Sequence $sequence): void
{
foreach ($sequence->getElements() as $childSequence) {
if ($childSequence instanceof Group) {
if ($childSequence instanceof Group) {
$this->visitGroup($class, $schema, $childSequence);
} else {
} elseif ($childSequence instanceof Choice) {
$this->visitChoice($class, $schema, $childSequence);
} else {
$property = $this->visitElement($class, $schema, $childSequence);
$class->addProperty($property);
}
}
}

/**
* Process xsd:complexType xsd:choice xsd:element
*
* @param PHPClass $class
* @param Schema $schema
* @param Choice $choice
*/
private function visitChoice(PHPClass $class, Schema $schema, Choice $choice)
private function visitChoice(PHPClass $class, Schema $schema, Choice $choice): void
{
foreach ($choice->getElements() as $choiceOption) {
if ($choiceOption instanceof Sequence) {
Expand All @@ -157,8 +159,8 @@ private function visitChoice(PHPClass $class, Schema $schema, Choice $choice)
}
}
}
private function visitGroup(PHPClass $class, Schema $schema, Group $group)

private function visitGroup(PHPClass $class, Schema $schema, Group $group): void
{
foreach ($group->getElements() as $childGroup) {
if ($childGroup instanceof Group) {
Expand All @@ -170,7 +172,7 @@ private function visitGroup(PHPClass $class, Schema $schema, Group $group)
}
}

private function visitAttributeGroup(PHPClass $class, Schema $schema, AttributeGroup $att)
private function visitAttributeGroup(PHPClass $class, Schema $schema, AttributeGroup $att): void
{
foreach ($att->getAttributes() as $childAttr) {
if ($childAttr instanceof AttributeGroup) {
Expand Down Expand Up @@ -223,7 +225,7 @@ public function visitElementDef(ElementDef $element)
return $this->classes[spl_object_hash($element)]['class'];
}

public function isSkip($class)
public function isSkip($class): bool
{
return !empty($this->skipByType[spl_object_hash($class)]);
}
Expand Down Expand Up @@ -340,7 +342,7 @@ private function visitTypeAnonymous(Type $type, $name, PHPClass $parentClass)
return $this->classes[spl_object_hash($type)]['class'];
}

private function visitComplexType(PHPClass $class, ComplexType $type)
private function visitComplexType(PHPClass $class, ComplexType $type): void
{
$schema = $type->getSchema();
foreach ($type->getElements() as $element) {
Expand All @@ -357,7 +359,7 @@ private function visitComplexType(PHPClass $class, ComplexType $type)
}
}

private function visitSimpleType(PHPClass $class, SimpleType $type)
private function visitSimpleType(PHPClass $class, SimpleType $type): void
{
if ($restriction = $type->getRestriction()) {
$parent = $restriction->getBase();
Expand Down Expand Up @@ -387,7 +389,7 @@ private function visitSimpleType(PHPClass $class, SimpleType $type)
}
}

private function handleClassExtension(PHPClass $class, Type $type)
private function handleClassExtension(PHPClass $class, Type $type): void
{
if ($alias = $this->getTypeAlias($type)) {
$c = PHPClass::createFromFQCN($alias);
Expand All @@ -401,7 +403,7 @@ private function handleClassExtension(PHPClass $class, Type $type)
}
}

private function visitBaseComplexType(PHPClass $class, BaseComplexType $type)
private function visitBaseComplexType(PHPClass $class, BaseComplexType $type): void
{
$parent = $type->getParent();
if ($parent) {
Expand Down

0 comments on commit 3f5d4fe

Please sign in to comment.