Skip to content

Commit 41809a1

Browse files
#8 Apply phpstan level 10
1 parent 8043178 commit 41809a1

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 10
33
paths:
44
- src
55
- tests

src/Client/Client.php

+13-17
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,20 @@
2323
class Client implements ClientInterface
2424
{
2525
/** @var array<mixed>|null */
26-
private $soapOptions;
26+
private ?array $soapOptions = null;
2727

2828
/** @var \SoapHeader[]|null */
29-
private $soapHeaders;
29+
private ?array $soapHeaders = null;
3030

31-
/** @var \SoapClient */
32-
private $soapClient;
31+
private ?\SoapClient $soapClient = null;
3332

34-
/** @var string */
35-
private $lastRequest;
33+
private ?string $lastRequest = null;
3634

37-
/** @var string */
38-
private $lastRequestHeaders;
35+
private ?string $lastRequestHeaders = null;
3936

40-
/** @var string */
41-
private $lastResponse;
37+
private ?string $lastResponse = null;
4238

43-
/** @var string */
44-
private $lastResponseHeaders;
39+
private ?string $lastResponseHeaders = null;
4540

4641
/**
4742
* Client constructor.
@@ -231,11 +226,12 @@ protected function initializeSoapClient(): void
231226

232227
protected function getLastRequestTrace(): void
233228
{
234-
if ($this->getSoapClient() instanceof \SoapClient) {
235-
$this->setLastRequest($this->getSoapClient()->__getLastRequest());
236-
$this->setLastRequestHeaders($this->getSoapClient()->__getLastRequestHeaders());
237-
$this->setLastResponse($this->getSoapClient()->__getLastResponse());
238-
$this->setLastResponseHeaders($this->getSoapClient()->__getLastResponseHeaders());
229+
$soapClient = $this->getSoapClient();
230+
if ($soapClient instanceof \SoapClient) {
231+
$this->setLastRequest($soapClient->__getLastRequest());
232+
$this->setLastRequestHeaders($soapClient->__getLastRequestHeaders());
233+
$this->setLastResponse($soapClient->__getLastResponse());
234+
$this->setLastResponseHeaders($soapClient->__getLastResponseHeaders());
239235
}
240236
}
241237

src/Task/RequestTask.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
use Symfony\Component\OptionsResolver\Options;
2222
use Symfony\Component\OptionsResolver\OptionsResolver;
2323

24+
/**
25+
* @phpstan-type RequestOptions array{
26+
* 'client': string,
27+
* 'method': string,
28+
* 'soap_call_options': array<mixed>|null,
29+
* 'soap_call_headers': array<\SoapHeader>|null,
30+
* }
31+
*/
2432
class RequestTask extends AbstractConfigurableTask
2533
{
2634
public function __construct(protected LoggerInterface $logger, protected ClientRegistry $registry)
@@ -29,15 +37,20 @@ public function __construct(protected LoggerInterface $logger, protected ClientR
2937

3038
public function execute(ProcessState $state): void
3139
{
40+
/** @var RequestOptions $options */
3241
$options = $this->getOptions($state);
3342

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

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

39-
$client->setSoapOptions($this->getOption($state, 'soap_call_options'));
40-
$client->setSoapHeaders($this->getOption($state, 'soap_call_headers'));
48+
/** @var array<mixed>|null $soapCallOptions */
49+
$soapCallOptions = $this->getOption($state, 'soap_call_options');
50+
$client->setSoapOptions($soapCallOptions);
51+
/** @var array<\SoapHeader>|null $soapCallHeaders */
52+
$soapCallHeaders = $this->getOption($state, 'soap_call_headers');
53+
$client->setSoapHeaders($soapCallHeaders);
4154

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

@@ -93,7 +106,9 @@ protected function configureOptions(OptionsResolver $resolver): void
93106
$this->configureSoapCallHeaderOption($headerResolver);
94107

95108
$resolvedHeaders = [];
109+
/** @var array<string, array<mixed>> $headers */
96110
foreach ($headers as $name => $header) {
111+
/** @var array{'namespace': string, 'data': array<mixed>} $resolvedHeader */
97112
$resolvedHeader = $headerResolver->resolve($header);
98113
$resolvedHeaders[] = new \SoapHeader($resolvedHeader['namespace'], $name, $resolvedHeader['data']);
99114
}

src/Transformer/RequestTransformer.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\OptionsResolver\OptionsResolver;
1919

2020
/**
21-
* @phpstan-type Options array{
21+
* @phpstan-type TransformerOptions array{
2222
* 'client': string,
2323
* 'method': string,
2424
* }
@@ -34,9 +34,13 @@ public function __construct(protected ClientRegistry $registry)
3434
*/
3535
public function transform(mixed $value, array $options = []): mixed
3636
{
37+
if (!\is_array($value)) {
38+
throw new \UnexpectedValueException('Expecting an array of value');
39+
}
40+
3741
$resolver = new OptionsResolver();
3842
$this->configureOptions($resolver);
39-
/** @var Options $options */
43+
/** @var TransformerOptions $options */
4044
$options = $resolver->resolve($options);
4145

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

0 commit comments

Comments
 (0)