Skip to content

Commit aaa5243

Browse files
#8 Remove all phpstan ignoreErrors, exceptp parameter.defaultValue because of OptionsResolver. Fix code.
1 parent 95dea37 commit aaa5243

File tree

4 files changed

+63
-16
lines changed

4 files changed

+63
-16
lines changed

phpstan.neon

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,4 @@ parameters:
44
- src
55
- tests
66
ignoreErrors:
7-
- '#type has no value type specified in iterable type#'
8-
- '#has parameter .* with no value type specified in iterable type#'
9-
- '#has no value type specified in iterable type array#'
10-
- '#configureOptions\(\) has no return type specified.#'
11-
- '#configure\(\) has no return type specified#'
12-
- '#process\(\) has no return type specified#'
13-
- '#should return Iterator but returns Traversable#'
14-
- '#Negated boolean expression is always false#'
15-
checkGenericClassInNonGenericObjectType: false
16-
reportUnmatchedIgnoredErrors: false
17-
inferPrivatePropertyTypeFromConstructor: true
18-
treatPhpDocTypesAsCertain: false
7+
- identifier: parameter.defaultValue

src/Client/Client.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Symfony\Contracts\HttpClient\HttpClientInterface;
2020
use Symfony\Contracts\HttpClient\ResponseInterface;
2121

22+
/**
23+
* @phpstan-import-type Options from \CleverAge\RestProcessBundle\Task\RequestTask
24+
*/
2225
class Client implements ClientInterface
2326
{
2427
public function __construct(
@@ -50,6 +53,8 @@ public function setUri(string $uri): void
5053
}
5154

5255
/**
56+
* @param Options $options
57+
*
5358
* @throws RestRequestException
5459
*/
5560
public function call(array $options = []): ResponseInterface
@@ -70,7 +75,7 @@ public function call(array $options = []): ResponseInterface
7075
$this->getRequestUri($options),
7176
$this->getRequestOptions($options),
7277
);
73-
} catch (\Exception|\Throwable $e) {
78+
} catch (\Throwable $e) {
7479
$this->logger->error(
7580
'Rest request failed',
7681
[
@@ -110,6 +115,11 @@ protected function configureOptions(OptionsResolver $resolver): void
110115
$resolver->setAllowedTypes('data', ['array', 'string', 'null']);
111116
}
112117

118+
/**
119+
* @param Options $options
120+
*
121+
* @return Options
122+
*/
113123
protected function getOptions(array $options = []): array
114124
{
115125
$resolver = new OptionsResolver();
@@ -118,11 +128,24 @@ protected function getOptions(array $options = []): array
118128
return $resolver->resolve($options);
119129
}
120130

131+
/**
132+
* @param Options $options
133+
*/
121134
protected function getRequestUri(array $options = []): string
122135
{
123136
return $this->replaceParametersInUri($this->constructUri($options), $options);
124137
}
125138

139+
/**
140+
* @param Options $options
141+
*
142+
* @return array{
143+
* 'headers': array<mixed>,
144+
* 'json'?: array<mixed>|string|null,
145+
* 'query'?: array<mixed>|string|null,
146+
* 'body'?: array<mixed>|string|null
147+
* }
148+
*/
126149
protected function getRequestOptions(array $options = []): array
127150
{
128151
$requestOptions = [];
@@ -144,6 +167,9 @@ protected function getRequestOptions(array $options = []): array
144167
return $requestOptions;
145168
}
146169

170+
/**
171+
* @param Options $options
172+
*/
147173
protected function constructUri(array $options): string
148174
{
149175
$uri = ltrim((string) $options['url'], '/');
@@ -156,9 +182,12 @@ protected function getApiUrl(): string
156182
return $this->geUri();
157183
}
158184

185+
/**
186+
* @param Options $options
187+
*/
159188
protected function replaceParametersInUri(string $uri, array $options = []): string
160189
{
161-
if (\array_key_exists('url_parameters', $options) && $options['url_parameters']) {
190+
if ($options['url_parameters']) {
162191
$search = array_keys($options['url_parameters']);
163192
array_walk(
164193
$search,

src/Client/ClientInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
use Symfony\Contracts\HttpClient\ResponseInterface;
1717

18+
/**
19+
* @phpstan-import-type Options from \CleverAge\RestProcessBundle\Task\RequestTask
20+
*/
1821
interface ClientInterface
1922
{
2023
/**
@@ -26,5 +29,8 @@ public function geUri(): string;
2629

2730
public function setUri(string $uri): void;
2831

32+
/**
33+
* @param Options $options
34+
*/
2935
public function call(array $options = []): ResponseInterface;
3036
}

src/Task/RequestTask.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,22 @@
2222
use Symfony\Component\OptionsResolver\Exception\AccessException;
2323
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
2424
use Symfony\Component\OptionsResolver\OptionsResolver;
25-
25+
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
26+
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
27+
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
28+
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
29+
30+
/**
31+
* @phpstan-type Options array{
32+
* 'url': string,
33+
* 'method': string,
34+
* 'headers': array<mixed>,
35+
* 'url_parameters': array<mixed>,
36+
* 'sends': string,
37+
* 'expects': string,
38+
* 'data': array<mixed>|string|null
39+
* }
40+
*/
2641
class RequestTask extends AbstractConfigurableTask
2742
{
2843
public function __construct(protected LoggerInterface $logger, protected ClientRegistry $registry)
@@ -31,6 +46,11 @@ public function __construct(protected LoggerInterface $logger, protected ClientR
3146

3247
/**
3348
* @throws MissingClientException
49+
* @throws ClientExceptionInterface
50+
* @throws RedirectionExceptionInterface
51+
* @throws ServerExceptionInterface
52+
* @throws TransportExceptionInterface
53+
* @throws \Throwable
3454
*/
3555
public function execute(ProcessState $state): void
3656
{
@@ -68,7 +88,7 @@ public function execute(ProcessState $state): void
6888
}
6989

7090
$state->setOutput($response->getContent());
71-
} catch (\Exception|\Throwable $e) {
91+
} catch (\Throwable $e) {
7292
$this->logger->error(
7393
'REST request failed',
7494
[
@@ -116,6 +136,9 @@ protected function configureOptions(OptionsResolver $resolver): void
116136
$resolver->setAllowedTypes('log_response', ['bool']);
117137
}
118138

139+
/**
140+
* @return Options
141+
*/
119142
protected function getRequestOptions(ProcessState $state): array
120143
{
121144
$options = $this->getOptions($state);

0 commit comments

Comments
 (0)