Skip to content

Commit 60a0b82

Browse files
#8 Apply phpstan level 10
1 parent aaa5243 commit 60a0b82

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
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

+14-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\Contracts\HttpClient\ResponseInterface;
2121

2222
/**
23-
* @phpstan-import-type Options from \CleverAge\RestProcessBundle\Task\RequestTask
23+
* @phpstan-import-type RequestOptions from \CleverAge\RestProcessBundle\Task\RequestTask
2424
*/
2525
class Client implements ClientInterface
2626
{
@@ -53,7 +53,7 @@ public function setUri(string $uri): void
5353
}
5454

5555
/**
56-
* @param Options $options
56+
* @param RequestOptions $options
5757
*
5858
* @throws RestRequestException
5959
*/
@@ -116,28 +116,31 @@ protected function configureOptions(OptionsResolver $resolver): void
116116
}
117117

118118
/**
119-
* @param Options $options
119+
* @param RequestOptions $options
120120
*
121-
* @return Options
121+
* @return RequestOptions
122122
*/
123123
protected function getOptions(array $options = []): array
124124
{
125125
$resolver = new OptionsResolver();
126126
$this->configureOptions($resolver);
127127

128-
return $resolver->resolve($options);
128+
/** @var RequestOptions $resolved */
129+
$resolved = $resolver->resolve($options);
130+
131+
return $resolved;
129132
}
130133

131134
/**
132-
* @param Options $options
135+
* @param RequestOptions $options
133136
*/
134137
protected function getRequestUri(array $options = []): string
135138
{
136139
return $this->replaceParametersInUri($this->constructUri($options), $options);
137140
}
138141

139142
/**
140-
* @param Options $options
143+
* @param RequestOptions $options
141144
*
142145
* @return array{
143146
* 'headers': array<mixed>,
@@ -168,7 +171,7 @@ protected function getRequestOptions(array $options = []): array
168171
}
169172

170173
/**
171-
* @param Options $options
174+
* @param RequestOptions $options
172175
*/
173176
protected function constructUri(array $options): string
174177
{
@@ -183,18 +186,20 @@ protected function getApiUrl(): string
183186
}
184187

185188
/**
186-
* @param Options $options
189+
* @param RequestOptions $options
187190
*/
188191
protected function replaceParametersInUri(string $uri, array $options = []): string
189192
{
190193
if ($options['url_parameters']) {
194+
/** @var array<string> $search */
191195
$search = array_keys($options['url_parameters']);
192196
array_walk(
193197
$search,
194198
static function (&$item, $key) {
195199
$item = '{'.$item.'}';
196200
}
197201
);
202+
/** @var array<string> $replace */
198203
$replace = array_values($options['url_parameters']);
199204
array_walk(
200205
$replace,

src/Client/ClientInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Contracts\HttpClient\ResponseInterface;
1717

1818
/**
19-
* @phpstan-import-type Options from \CleverAge\RestProcessBundle\Task\RequestTask
19+
* @phpstan-import-type RequestOptions from \CleverAge\RestProcessBundle\Task\RequestTask
2020
*/
2121
interface ClientInterface
2222
{
@@ -30,7 +30,7 @@ public function geUri(): string;
3030
public function setUri(string $uri): void;
3131

3232
/**
33-
* @param Options $options
33+
* @param RequestOptions $options
3434
*/
3535
public function call(array $options = []): ResponseInterface;
3636
}

src/Task/RequestTask.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,26 @@
2929

3030
/**
3131
* @phpstan-type Options array{
32+
* 'client': string,
33+
* 'url': string,
34+
* 'method': string,
35+
* 'headers': array<mixed>,
36+
* 'url_parameters': array<mixed>,
37+
* 'data': array<mixed>|string|null,
38+
* 'sends': string,
39+
* 'expects': string,
40+
* 'valid_response_code': array<int>,
41+
* 'log_response': bool,
42+
* }
43+
* @phpstan-type RequestOptions array{
3244
* 'url': string,
3345
* 'method': string,
3446
* 'headers': array<mixed>,
3547
* 'url_parameters': array<mixed>,
3648
* 'sends': string,
3749
* 'expects': string,
3850
* 'data': array<mixed>|string|null
39-
* }
51+
* }
4052
*/
4153
class RequestTask extends AbstractConfigurableTask
4254
{
@@ -54,6 +66,7 @@ public function __construct(protected LoggerInterface $logger, protected ClientR
5466
*/
5567
public function execute(ProcessState $state): void
5668
{
69+
/** @var Options $options */
5770
$options = $this->getOptions($state);
5871

5972
$requestOptions = $this->getRequestOptions($state);
@@ -137,10 +150,11 @@ protected function configureOptions(OptionsResolver $resolver): void
137150
}
138151

139152
/**
140-
* @return Options
153+
* @return RequestOptions
141154
*/
142155
protected function getRequestOptions(ProcessState $state): array
143156
{
157+
/** @var Options $options */
144158
$options = $this->getOptions($state);
145159

146160
$requestOptions = [
@@ -153,8 +167,12 @@ protected function getRequestOptions(ProcessState $state): array
153167
'data' => $options['data'],
154168
];
155169

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

158-
return array_merge($requestOptions, $input);
173+
/** @var RequestOptions $mergedOptions */
174+
$mergedOptions = array_merge($requestOptions, $input);
175+
176+
return $mergedOptions;
159177
}
160178
}

0 commit comments

Comments
 (0)