Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 1 addition & 14 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
parameters:
level: 6
level: 10
paths:
- src
- tests
ignoreErrors:
- '#type has no value type specified in iterable type#'
- '#has parameter .* with no value type specified in iterable type#'
- '#has no value type specified in iterable type array#'
- '#configureOptions\(\) has no return type specified.#'
- '#configure\(\) has no return type specified#'
- '#process\(\) has no return type specified#'
- '#should return Iterator but returns Traversable#'
- '#Negated boolean expression is always false#'
checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
48 changes: 26 additions & 22 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,21 @@
*/
class Client implements ClientInterface
{
/** @var array */
private $soapOptions;
/** @var array<mixed>|null */
private ?array $soapOptions = null;

/** @var \SoapHeader[]|null */
private $soapHeaders;
private ?array $soapHeaders = null;

/** @var \SoapClient */
private $soapClient;
private ?\SoapClient $soapClient = null;

/** @var string */
private $lastRequest;
private ?string $lastRequest = null;

/** @var string */
private $lastRequestHeaders;
private ?string $lastRequestHeaders = null;

/** @var string */
private $lastResponse;
private ?string $lastResponse = null;

/** @var string */
private $lastResponseHeaders;
private ?string $lastResponseHeaders = null;

/**
* Client constructor.
Expand All @@ -50,6 +45,7 @@ public function __construct(
private readonly LoggerInterface $logger,
private readonly string $code,
private ?string $wsdl,
/** @var array<mixed> */
private array $options = [],
) {
}
Expand Down Expand Up @@ -167,9 +163,6 @@ public function setLastResponseHeaders(?string $lastResponseHeaders): void
$this->lastResponseHeaders = $lastResponseHeaders;
}

/**
* @return bool|mixed
*/
public function call(string $method, array $input = []): mixed
{
$this->initializeSoapClient();
Expand All @@ -187,6 +180,8 @@ public function call(string $method, array $input = []): mixed
}

/**
* @param array<mixed> $input
*
* @return bool|mixed
*/
protected function doSoapCall(string $method, array $input = []): mixed
Expand All @@ -196,7 +191,7 @@ protected function doSoapCall(string $method, array $input = []): mixed
}
try {
$result = $this->getSoapClient()->__soapCall($method, $input, $this->getSoapOptions(), $this->getSoapHeaders());
} /* @noinspection PhpRedundantCatchClauseInspection */ catch (\SoapFault $e) {
} catch (\SoapFault $e) {
$this->getLastRequestTrace();
$this->getLogger()->alert(
\sprintf("Soap call '%s' on '%s' failed : %s", $method, $this->getWsdl(), $e->getMessage()),
Expand Down Expand Up @@ -231,14 +226,23 @@ protected function initializeSoapClient(): void

protected function getLastRequestTrace(): void
{
if ($this->getSoapClient() instanceof \SoapClient) {
$this->setLastRequest($this->getSoapClient()->__getLastRequest());
$this->setLastRequestHeaders($this->getSoapClient()->__getLastRequestHeaders());
$this->setLastResponse($this->getSoapClient()->__getLastResponse());
$this->setLastResponseHeaders($this->getSoapClient()->__getLastResponseHeaders());
$soapClient = $this->getSoapClient();
if ($soapClient instanceof \SoapClient) {
$this->setLastRequest($soapClient->__getLastRequest());
$this->setLastRequestHeaders($soapClient->__getLastRequestHeaders());
$this->setLastResponse($soapClient->__getLastResponse());
$this->setLastResponseHeaders($soapClient->__getLastResponseHeaders());
}
}

/**
* @return array{
* 'LastRequest': ?string,
* 'LastRequestHeaders': ?string,
* 'LastResponse': ?string,
* 'LastResponseHeaders': ?string
* }
*/
protected function getLastRequestTraceArray(): array
{
return [
Expand Down
10 changes: 10 additions & 0 deletions src/Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,35 @@ public function setWsdl(?string $wsdl): void;
* Return the Soap client options.
*
* @see http://php.net/manual/en/soapclient.soapclient.php
*
* @return array<mixed>
*/
public function getOptions(): array;

/**
* Set the Soap client options.
*
* @see http://php.net/manual/en/soapclient.soapclient.php
*
* @param array<mixed> $options
*/
public function setOptions(array $options): void;

/**
* Return the Soap call options.
*
* @see https://www.php.net/manual/en/soapclient.soapcall.php
*
* @return array<mixed>|null
*/
public function getSoapOptions(): ?array;

/**
* Set the Soap call options.
*
* @see https://www.php.net/manual/en/soapclient.soapcall.php
*
* @param array<mixed>|null $options
*/
public function setSoapOptions(?array $options = null): void;

Expand Down Expand Up @@ -87,6 +95,8 @@ public function getLastResponseHeaders(): ?string;
/**
* Call Soap method.
*
* @param array<mixed> $input
*
* @return bool|mixed
*/
public function call(string $method, array $input = []): mixed;
Expand Down
20 changes: 18 additions & 2 deletions src/Task/RequestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @phpstan-type RequestOptions array{
* 'client': string,
* 'method': string,
* 'soap_call_options': array<mixed>|null,
* 'soap_call_headers': array<\SoapHeader>|null,
* }
*/
class RequestTask extends AbstractConfigurableTask
{
public function __construct(protected LoggerInterface $logger, protected ClientRegistry $registry)
Expand All @@ -29,14 +37,20 @@ public function __construct(protected LoggerInterface $logger, protected ClientR

public function execute(ProcessState $state): void
{
/** @var RequestOptions $options */
$options = $this->getOptions($state);

$client = $this->registry->getClient($options['client']);

/** @var array<mixed> $input */
$input = $state->getInput() ?: [];

$client->setSoapOptions($this->getOption($state, 'soap_call_options'));
$client->setSoapHeaders($this->getOption($state, 'soap_call_headers'));
/** @var array<mixed>|null $soapCallOptions */
$soapCallOptions = $this->getOption($state, 'soap_call_options');
$client->setSoapOptions($soapCallOptions);
/** @var array<\SoapHeader>|null $soapCallHeaders */
$soapCallHeaders = $this->getOption($state, 'soap_call_headers');
$client->setSoapHeaders($soapCallHeaders);

$result = $client->call($options['method'], $input);

Expand Down Expand Up @@ -92,7 +106,9 @@ protected function configureOptions(OptionsResolver $resolver): void
$this->configureSoapCallHeaderOption($headerResolver);

$resolvedHeaders = [];
/** @var array<string, array<mixed>> $headers */
foreach ($headers as $name => $header) {
/** @var array{'namespace': string, 'data': array<mixed>} $resolvedHeader */
$resolvedHeader = $headerResolver->resolve($header);
$resolvedHeaders[] = new \SoapHeader($resolvedHeader['namespace'], $name, $resolvedHeader['data']);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Transformer/RequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,30 @@
use CleverAge\SoapProcessBundle\Registry\ClientRegistry;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @phpstan-type TransformerOptions array{
* 'client': string,
* 'method': string,
* }
*/
class RequestTransformer implements ConfigurableTransformerInterface
{
public function __construct(protected ClientRegistry $registry)
{
}

/**
* @param array<mixed> $options
*/
public function transform(mixed $value, array $options = []): mixed
{
if (!\is_array($value)) {
throw new \UnexpectedValueException('Expecting an array of value');
}

$resolver = new OptionsResolver();
$this->configureOptions($resolver);
/** @var TransformerOptions $options */
$options = $resolver->resolve($options);

$client = $this->registry->getClient($options['client']);
Expand Down
Loading