Skip to content

Commit

Permalink
Merge pull request #553 from veewee/client-method-simple-element-support
Browse files Browse the repository at this point in the history
Add support for simple element return types in soap methods
  • Loading branch information
veewee authored Oct 25, 2024
2 parents 78933b6 + cbd3d5d commit 73e840c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/Phpro/SoapClient/CodeGenerator/Model/ReturnTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ function it_has_a_type()
$this->getType()->shouldReturn('\\My\\Namespace\\Type');
}

function it_can_fall_back_to_mixed_on_unkown_extension_of_simple_type()
{
$this->beConstructedWith(
'Type',
'My\Namespace',
XsdType::create('Type')
->withMeta(static fn (TypeMeta $meta) => $meta->withIsSimple(true))
);

$this->getType()->shouldReturn('mixed');
}

function it_can_fall_back_to_simple_type()
{
$this->beConstructedWith(
'Type',
'My\Namespace',
XsdType::create('Type')
->withMeta(static fn (TypeMeta $meta) => $meta->withIsSimple(true)->withExtends([
'isSimple' => true,
'type' => 'string',
'namespace' => 'http://www.w3.org/2001/XMLSchema',
]))
);

$this->getType()->shouldReturn('string');
}

public function it_has_type_meta(): void
{
$this->getMeta()->shouldBeLike(new TypeMeta());
Expand Down
7 changes: 7 additions & 0 deletions src/Phpro/SoapClient/CodeGenerator/Model/ReturnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public function getType(): string
if (Normalizer::isKnownType($this->type)) {
return $this->type;
}

if ($this->meta->isSimple()->unwrapOr(false)) {
return $this->meta->extends()
->filter(static fn (array $extends): bool => $extends['isSimple'])
->map(static fn (array $extends): string => $extends['type'])
->unwrapOr('mixed');
}

return '\\'.$this->namespace.'\\'.Normalizer::normalizeClassname($this->type);
}
Expand Down

0 comments on commit 73e840c

Please sign in to comment.