Skip to content

Commit 65cb638

Browse files
feat(transport): add phpstan generics for typed transport returns
1 parent dbb29ca commit 65cb638

File tree

11 files changed

+26
-11
lines changed

11 files changed

+26
-11
lines changed

examples/custom-method-handlers/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ public function handle(CallToolRequest|HasMethodInterface $message, SessionInter
141141

142142
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
143143

144-
exit((int) $result);
144+
exit($result);

examples/stdio-cached-discovery/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535

3636
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
3737

38-
exit((int) $result);
38+
exit($result);

examples/stdio-custom-dependencies/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343

4444
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
4545

46-
exit((int) $result);
46+
exit($result);

examples/stdio-discovery-calculator/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232

3333
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
3434

35-
exit((int) $result);
35+
exit($result);

examples/stdio-env-variables/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161

6262
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
6363

64-
exit((int) $result);
64+
exit($result);

examples/stdio-explicit-registration/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535

3636
logger()->info('Server listener stopped gracefully.', ['result' => $result]);
3737

38-
exit((int) $result);
38+
exit($result);

src/Server.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public static function builder(): Builder
3535
return new Builder();
3636
}
3737

38+
/**
39+
* @template TResult
40+
*
41+
* @param TransportInterface<TResult> $transport
42+
*
43+
* @return TResult
44+
*/
3845
public function run(TransportInterface $transport): mixed
3946
{
4047
$transport->initialize();

src/Server/Transport/InMemoryTransport.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Uid\Uuid;
1515

1616
/**
17+
* @implements TransportInterface<null>
18+
*
1719
* @author Tobias Nyholm <[email protected]>
1820
*/
1921
class InMemoryTransport implements TransportInterface
@@ -50,7 +52,7 @@ public function send(string $data, array $context): void
5052
}
5153
}
5254

53-
public function listen(): mixed
55+
public function listen(): null
5456
{
5557
foreach ($this->messages as $message) {
5658
if (\is_callable($this->messageListener)) {
@@ -63,7 +65,7 @@ public function listen(): mixed
6365
$this->sessionId = null;
6466
}
6567

66-
return 0;
68+
return null;
6769
}
6870

6971
public function onSessionEnd(callable $listener): void

src/Server/Transport/StdioTransport.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\Uid\Uuid;
1717

1818
/**
19+
* @implements TransportInterface<int>
20+
*
1921
* @author Kyrian Obikwelu <[email protected]>
2022
*/
2123
class StdioTransport implements TransportInterface
@@ -59,7 +61,7 @@ public function send(string $data, array $context): void
5961
fwrite($this->output, $data.\PHP_EOL);
6062
}
6163

62-
public function listen(): mixed
64+
public function listen(): int
6365
{
6466
$this->logger->info('StdioTransport is listening for messages on STDIN...');
6567

src/Server/Transport/StreamableHttpTransport.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Symfony\Component\Uid\Uuid;
2222

2323
/**
24+
* @implements TransportInterface<ResponseInterface>
25+
*
2426
* @author Kyrian Obikwelu <[email protected]>
2527
*/
2628
class StreamableHttpTransport implements TransportInterface
@@ -78,7 +80,7 @@ public function send(string $data, array $context): void
7880
]);
7981
}
8082

81-
public function listen(): mixed
83+
public function listen(): ResponseInterface
8284
{
8385
return match ($this->request->getMethod()) {
8486
'OPTIONS' => $this->handleOptionsRequest(),

0 commit comments

Comments
 (0)