@@ -42,8 +42,7 @@ class HttpWorker implements HttpWorkerInterface
4242
4343 public function __construct (
4444 private readonly WorkerInterface $ worker ,
45- ) {
46- }
45+ ) {}
4746
4847 public function getWorker (): WorkerInterface
4948 {
@@ -83,13 +82,13 @@ public function waitRequest(): ?Request
8382 * @param array<array-key, array<array-key, string>> $headers
8483 * @throws \JsonException
8584 */
86- public function respond (int $ status , string |Generator $ body = '' , array $ headers = [], bool $ endOfStream = true ): void
85+ public function respond (int $ status , string |\ Generator $ body = '' , array $ headers = [], bool $ endOfStream = true ): void
8786 {
8887 if ($ status < 200 && $ status >= 100 && $ body !== '' ) {
8988 throw new \InvalidArgumentException ('Unable to send a body with informational status code. ' );
9089 }
9190
92- if ($ body instanceof Generator) {
91+ if ($ body instanceof \ Generator) {
9392 $ this ->respondStream ($ status , $ body , $ headers , $ endOfStream );
9493 return ;
9594 }
@@ -101,7 +100,7 @@ public function respond(int $status, string|Generator $body = '', array $headers
101100 /**
102101 * @param array<array-key, array<array-key, string>> $headers
103102 */
104- private function respondStream (int $ status , Generator $ body , array $ headers = [], bool $ endOfStream = true ): void
103+ private function respondStream (int $ status , \ Generator $ body , array $ headers = [], bool $ endOfStream = true ): void
105104 {
106105 $ worker = $ this ->worker instanceof StreamWorkerInterface
107106 ? $ this ->worker ->withStreamMode ()
@@ -110,20 +109,20 @@ private function respondStream(int $status, Generator $body, array $headers = []
110109 do {
111110 if (!$ body ->valid ()) {
112111 // End of generator
113- $ content = (string )$ body ->getReturn ();
112+ $ content = (string ) $ body ->getReturn ();
114113 if ($ endOfStream === false && $ content === '' ) {
115114 // We don't need to send an empty frame if the stream is not ended
116115 return ;
117116 }
118117 /** @psalm-suppress TooManyArguments */
119118 $ worker ->respond (
120119 $ this ->createRespondPayload ($ status , $ content , $ headers , $ endOfStream ),
121- static ::$ codec
120+ static ::$ codec,
122121 );
123122 break ;
124123 }
125124
126- $ content = (string )$ body ->current ();
125+ $ content = (string ) $ body ->current ();
127126 if ($ worker ->getPayload (StreamStop::class) !== null ) {
128127 $ body ->throw (new StreamStoppedException ());
129128
@@ -160,12 +159,12 @@ private function arrayToRequest(string $body, array $context): Request
160159 protocol: $ context ['protocol ' ],
161160 method: $ context ['method ' ],
162161 uri: $ context ['uri ' ],
163- headers: $ this ->filterHeaders ((array )($ context ['headers ' ] ?? [])),
164- cookies: (array )($ context ['cookies ' ] ?? []),
165- uploads: (array )($ context ['uploads ' ] ?? []),
162+ headers: $ this ->filterHeaders ((array ) ($ context ['headers ' ] ?? [])),
163+ cookies: (array ) ($ context ['cookies ' ] ?? []),
164+ uploads: (array ) ($ context ['uploads ' ] ?? []),
166165 attributes: [
167166 Request::PARSED_BODY_ATTRIBUTE_NAME => $ context ['parsed ' ],
168- ] + (array )($ context ['attributes ' ] ?? []),
167+ ] + (array ) ($ context ['attributes ' ] ?? []),
169168 query: $ query ,
170169 body: $ body ,
171170 parsed: $ context ['parsed ' ],
@@ -253,7 +252,7 @@ private function arrayToHeaderValue(array $headers = []): array
253252 */
254253 foreach ($ headers as $ key => $ value ) {
255254 /** @psalm-suppress DocblockTypeContradiction */
256- $ value = \array_filter (\is_array ($ value ) ? $ value : [$ value ], static fn (mixed $ v ): bool => \is_string ($ v ));
255+ $ value = \array_filter (\is_array ($ value ) ? $ value : [$ value ], static fn (mixed $ v ): bool => \is_string ($ v ));
257256 if ($ value !== []) {
258257 $ result [$ key ] = new HeaderValue (['value ' => $ value ]);
259258 }
@@ -270,7 +269,7 @@ private function createRespondPayload(int $status, string $body, array $headers
270269 $ head = static ::$ codec === Frame::CODEC_PROTO
271270 ? (new Response (['status ' => $ status , 'headers ' => $ this ->arrayToHeaderValue ($ headers )]))
272271 ->serializeToString ()
273- : \json_encode (['status ' => $ status , 'headers ' => $ headers ?: (object )[]], \JSON_THROW_ON_ERROR );
272+ : \json_encode (['status ' => $ status , 'headers ' => $ headers ?: (object ) []], \JSON_THROW_ON_ERROR );
274273
275274 return new Payload (body: $ body , header: $ head , eos: $ eos );
276275 }
0 commit comments