Skip to content

Commit

Permalink
Merge pull request #549 from veewee/improved-result-type-detector
Browse files Browse the repository at this point in the history
Detect linked complexTypes as ResultInterface as well
  • Loading branch information
veewee authored Sep 27, 2024
2 parents b6825d1 + 92875d9 commit a23f11d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@

use Soap\Engine\Metadata\Collection\MethodCollection;
use Soap\Engine\Metadata\Model\Method;
use function Psl\Dict\unique;
use function Psl\Vec\filter;
use function Psl\Vec\flat_map;
use function Psl\Vec\values;

final class ResponseTypesDetector
{
public function __invoke(MethodCollection $methods): array
{
return array_unique(array_map(
static function (Method $method): string {
return $method->getReturnType()->getName();
},
iterator_to_array($methods)
));
return values(
unique(
filter(
flat_map(
$methods,
static fn (Method $method): array => [
$method->getReturnType()->getName(),
$method->getReturnType()->getXmlTypeName()
]
)
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class ResponseTypesDetectorTest extends TestCase
public function it_can_detect_request_types(): void
{
$methods = new MethodCollection(
new Method('method1', new ParameterCollection(), XsdType::create('Response1')),
new Method('method1', new ParameterCollection(), XsdType::create('Response1')->withXmlTypeName('Response1')),
new Method('method3', new ParameterCollection(
new Parameter('param1', XsdType::create('RequestType2')),
new Parameter('param2', XsdType::create('RequestType3'))
), XsdType::create('Response2')),
), XsdType::create('Response2')->withXmlTypeName('LinkedResponse2ComplexType')),
new Method('method1', new ParameterCollection(), XsdType::create('string'))
);

$detected = (new ResponseTypesDetector())($methods);
self::assertSame(
['Response1', 'Response2', 'string'],
['Response1', 'Response2', 'LinkedResponse2ComplexType', 'string'],
$detected
);
}
Expand Down

0 comments on commit a23f11d

Please sign in to comment.