1919use Symfony \Contracts \HttpClient \HttpClientInterface ;
2020use Symfony \Contracts \HttpClient \ResponseInterface ;
2121
22+ /**
23+ * @phpstan-import-type RequestOptions from \CleverAge\RestProcessBundle\Task\RequestTask
24+ */
2225class Client implements ClientInterface
2326{
2427 public function __construct (
@@ -50,6 +53,8 @@ public function setUri(string $uri): void
5053 }
5154
5255 /**
56+ * @param RequestOptions $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,19 +115,40 @@ protected function configureOptions(OptionsResolver $resolver): void
110115 $ resolver ->setAllowedTypes ('data ' , ['array ' , 'string ' , 'null ' ]);
111116 }
112117
118+ /**
119+ * @param RequestOptions $options
120+ *
121+ * @return RequestOptions
122+ */
113123 protected function getOptions (array $ options = []): array
114124 {
115125 $ resolver = new OptionsResolver ();
116126 $ this ->configureOptions ($ resolver );
117127
118- return $ resolver ->resolve ($ options );
128+ /** @var RequestOptions $resolved */
129+ $ resolved = $ resolver ->resolve ($ options );
130+
131+ return $ resolved ;
119132 }
120133
134+ /**
135+ * @param RequestOptions $options
136+ */
121137 protected function getRequestUri (array $ options = []): string
122138 {
123139 return $ this ->replaceParametersInUri ($ this ->constructUri ($ options ), $ options );
124140 }
125141
142+ /**
143+ * @param RequestOptions $options
144+ *
145+ * @return array{
146+ * 'headers': array<mixed>,
147+ * 'json'?: array<mixed>|string|null,
148+ * 'query'?: array<mixed>|string|null,
149+ * 'body'?: array<mixed>|string|null
150+ * }
151+ */
126152 protected function getRequestOptions (array $ options = []): array
127153 {
128154 $ requestOptions = [];
@@ -144,6 +170,9 @@ protected function getRequestOptions(array $options = []): array
144170 return $ requestOptions ;
145171 }
146172
173+ /**
174+ * @param RequestOptions $options
175+ */
147176 protected function constructUri (array $ options ): string
148177 {
149178 $ uri = ltrim ((string ) $ options ['url ' ], '/ ' );
@@ -156,16 +185,21 @@ protected function getApiUrl(): string
156185 return $ this ->geUri ();
157186 }
158187
188+ /**
189+ * @param RequestOptions $options
190+ */
159191 protected function replaceParametersInUri (string $ uri , array $ options = []): string
160192 {
161- if (\array_key_exists ('url_parameters ' , $ options ) && $ options ['url_parameters ' ]) {
193+ if ($ options ['url_parameters ' ]) {
194+ /** @var array<string> $search */
162195 $ search = array_keys ($ options ['url_parameters ' ]);
163196 array_walk (
164197 $ search ,
165198 static function (&$ item , $ key ) {
166199 $ item = '{ ' .$ item .'} ' ;
167200 }
168201 );
202+ /** @var array<string> $replace */
169203 $ replace = array_values ($ options ['url_parameters ' ]);
170204 array_walk (
171205 $ replace ,
0 commit comments