Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #168 add choice-in-sequence handling #176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
goetas marked this conversation as resolved.
Show resolved Hide resolved
$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