Skip to content

Commit

Permalink
Address code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rauanmayemir committed Jan 13, 2025
1 parent a7e813f commit 1276246
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
5 changes: 0 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"3.x": "3.4.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
6 changes: 3 additions & 3 deletions src/Internal/CallContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ final class CallContext
* @param array<string, array<string>> $context
*/
public function __construct(
public string $service,
public string $method,
public array $context,
public readonly string $service,
public readonly string $method,
public readonly array $context,
) {
}

Expand Down
17 changes: 8 additions & 9 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,21 @@ public function serve(?WorkerInterface $worker = null, ?callable $finalize = nul

$response = $this->invoke($call->service, $call->method, $context, $request->body);

$headers = array_filter([
'headers' => $responseHeaders->count() ? $responseHeaders->packHeaders() : null,
'trailers' => $responseTrailers->count() ? $responseTrailers->packTrailers() : null,
]);
$headers = [];
$responseHeaders->count() === 0 or $headers['headers'] = $responseHeaders->packHeaders();
$responseTrailers->count() === 0 or $headers['trailers'] = $responseTrailers->packTrailers();

$this->workerSend(
worker: $worker,
body: $response,
headers: !empty($headers) ? Json::encode($headers) : '{}',
headers: $headers === [] ? '{}' : Json::encode($headers),
);
} catch (GRPCExceptionInterface $e) {
$headers = array_filter([
$headers = [
'error' => $this->createGrpcError($e),
'headers' => $responseHeaders->count() ? $responseHeaders->packHeaders() : null,
'trailers' => $responseTrailers->count() ? $responseTrailers->packTrailers() : null,
]);
];
$responseHeaders->count() === 0 or $headers['headers'] = $responseHeaders->packHeaders();
$responseTrailers->count() === 0 or $headers['trailers'] = $responseTrailers->packTrailers();

$this->workerSend(
worker: $worker,
Expand Down

0 comments on commit 1276246

Please sign in to comment.