Skip to content

Commit dc95211

Browse files
author
larry.sulebalogun
committed
10 - Fix all php-cs-fixer related issues
1 parent 10e7935 commit dc95211

File tree

7 files changed

+60
-58
lines changed

7 files changed

+60
-58
lines changed

src/Capability/Registry.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ public function getTools(?int $limit = null, ?string $cursor = null): array
313313
foreach ($this->tools as $toolReference) {
314314
$tools[] = $toolReference->tool;
315315
}
316-
317-
if ($limit === null) {
316+
317+
if (null === $limit) {
318318
return $tools;
319319
}
320-
320+
321321
return $this->paginateResults($tools, $limit, $cursor);
322322
}
323323

@@ -330,11 +330,11 @@ public function getResources(?int $limit = null, ?string $cursor = null): array
330330
foreach ($this->resources as $resource) {
331331
$resources[] = $resource->schema;
332332
}
333-
334-
if ($limit === null) {
333+
334+
if (null === $limit) {
335335
return $resources;
336336
}
337-
337+
338338
return $this->paginateResults($resources, $limit, $cursor);
339339
}
340340

@@ -347,11 +347,11 @@ public function getPrompts(?int $limit = null, ?string $cursor = null): array
347347
foreach ($this->prompts as $promptReference) {
348348
$prompts[] = $promptReference->prompt;
349349
}
350-
351-
if ($limit === null) {
350+
351+
if (null === $limit) {
352352
return $prompts;
353353
}
354-
354+
355355
return $this->paginateResults($prompts, $limit, $cursor);
356356
}
357357

@@ -360,36 +360,36 @@ public function getPrompts(?int $limit = null, ?string $cursor = null): array
360360
*/
361361
public function getToolsCount(): int
362362
{
363-
return count($this->tools);
363+
return \count($this->tools);
364364
}
365365

366366
/**
367367
* Get total count of prompts.
368368
*/
369369
public function getPromptsCount(): int
370370
{
371-
return count($this->prompts);
371+
return \count($this->prompts);
372372
}
373373

374374
/**
375375
* Get total count of resources.
376376
*/
377377
public function getResourcesCount(): int
378378
{
379-
return count($this->resources);
379+
return \count($this->resources);
380380
}
381381

382-
/**
383-
* @return array<string, ResourceTemplate>
382+
/**
383+
* @return array<string, ResourceTemplate>
384384
*/
385385
public function getResourceTemplates(?int $limit = null, ?string $cursor = null): array
386386
{
387387
$templates = array_map(fn ($template) => $template->resourceTemplate, $this->resourceTemplates);
388-
389-
if ($limit === null) {
388+
389+
if (null === $limit) {
390390
return $templates;
391391
}
392-
392+
393393
return $this->paginateResults($templates, $limit, $cursor);
394394
}
395395

@@ -399,22 +399,22 @@ public function getResourceTemplates(?int $limit = null, ?string $cursor = null)
399399
private function paginateResults(array $items, int $limit, ?string $cursor = null): array
400400
{
401401
$offset = 0;
402-
if ($cursor !== null) {
402+
if (null !== $cursor) {
403403
$decodedCursor = base64_decode($cursor, true);
404404

405-
if ($decodedCursor === false || !is_numeric($decodedCursor)) {
405+
if (false === $decodedCursor || !is_numeric($decodedCursor)) {
406406
throw new InvalidCursorException($cursor);
407407
}
408-
408+
409409
$offset = $decodedCursor;
410-
410+
411411
// Validate offset is within reasonable bounds
412-
if ($offset < 0 || $offset > count($items)) {
412+
if ($offset < 0 || $offset > \count($items)) {
413413
throw new InvalidCursorException($cursor);
414414
}
415415
}
416416

417-
return array_slice($items, $offset, $limit);
417+
return \array_slice($items, $offset, $limit);
418418
}
419419

420420
/**
@@ -424,20 +424,20 @@ public function calculateNextCursor(int $totalCount, ?string $currentCursor, int
424424
{
425425
$currentOffset = 0;
426426

427-
if ($currentCursor !== null) {
427+
if (null !== $currentCursor) {
428428
$decodedCursor = base64_decode($currentCursor, true);
429-
if ($decodedCursor !== false && is_numeric($decodedCursor)) {
429+
if (false !== $decodedCursor && is_numeric($decodedCursor)) {
430430
$currentOffset = $decodedCursor;
431431
}
432432
}
433-
433+
434434
$nextOffset = $currentOffset + $returnedCount;
435-
435+
436436
// If we have more items available, return next cursor
437437
if ($nextOffset < $totalCount) {
438438
return base64_encode((string) $nextOffset);
439439
}
440-
440+
441441
return null;
442442
}
443443
}

src/Server/RequestHandler/ListPromptsHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ final class ListPromptsHandler implements MethodHandlerInterface
2727
public function __construct(
2828
private readonly Registry $registry,
2929
private readonly int $pageSize = 20,
30-
) {}
30+
) {
31+
}
3132

3233
public function supports(HasMethodInterface $message): bool
3334
{

src/Server/RequestHandler/ListResourcesHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Mcp\Schema\JsonRpc\HasMethodInterface;
1717
use Mcp\Schema\JsonRpc\Response;
1818
use Mcp\Schema\Request\ListResourcesRequest;
19-
use Mcp\Schema\Resource;
2019
use Mcp\Schema\Result\ListResourcesResult;
2120
use Mcp\Server\MethodHandlerInterface;
2221

@@ -28,7 +27,8 @@ final class ListResourcesHandler implements MethodHandlerInterface
2827
public function __construct(
2928
private readonly Registry $registry,
3029
private readonly int $pageSize = 20,
31-
) {}
30+
) {
31+
}
3232

3333
public function supports(HasMethodInterface $message): bool
3434
{

src/Server/RequestHandler/ListToolsHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ final class ListToolsHandler implements MethodHandlerInterface
2828
public function __construct(
2929
private readonly Registry $registry,
3030
private readonly int $pageSize = 20,
31-
) {}
31+
) {
32+
}
3233

3334
public function supports(HasMethodInterface $message): bool
3435
{

tests/Server/RequestHandler/ListPromptsHandlerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testReturnsSecondPageWithCursor(): void
8282
$this->addPromptsToRegistry(10);
8383
$firstPageRequest = $this->createListPromptsRequest();
8484
$firstPageResponse = $this->handler->handle($firstPageRequest);
85-
85+
8686
$secondPageRequest = $this->createListPromptsRequest(cursor: $firstPageResponse->result->nextCursor);
8787

8888
// Act
@@ -107,7 +107,7 @@ public function testReturnsLastPageWithNullCursor(): void
107107
$this->addPromptsToRegistry(5);
108108
$firstPageRequest = $this->createListPromptsRequest();
109109
$firstPageResponse = $this->handler->handle($firstPageRequest);
110-
110+
111111
$secondPageRequest = $this->createListPromptsRequest(cursor: $firstPageResponse->result->nextCursor);
112112

113113
// Act
@@ -194,7 +194,7 @@ public function testMaintainsStableCursorsAcrossCalls(): void
194194
{
195195
// Arrange
196196
$this->addPromptsToRegistry(10);
197-
197+
198198
// Act
199199
$request = $this->createListPromptsRequest();
200200
$response1 = $this->handler->handle($request);
@@ -207,13 +207,13 @@ public function testMaintainsStableCursorsAcrossCalls(): void
207207

208208
private function addPromptsToRegistry(int $count): void
209209
{
210-
for ($i = 0; $i < $count; $i++) {
210+
for ($i = 0; $i < $count; ++$i) {
211211
$prompt = new Prompt(
212212
name: "prompt_$i",
213213
description: "Test prompt $i"
214214
);
215215

216-
$this->registry->registerPrompt($prompt, fn() => null);
216+
$this->registry->registerPrompt($prompt, fn () => null);
217217
}
218218
}
219219

@@ -223,9 +223,9 @@ private function createListPromptsRequest(?string $cursor = null): ListPromptsRe
223223
->setConstructorArgs([$cursor])
224224
->onlyMethods(['getId'])
225225
->getMock();
226-
226+
227227
$mock->method('getId')->willReturn('test-request-id');
228-
228+
229229
return $mock;
230230
}
231-
}
231+
}

tests/Server/RequestHandler/ListResourcesHandlerTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Mcp\Capability\Registry;
1515
use Mcp\Exception\InvalidCursorException;
16-
use Mcp\Schema\Resource;
1716
use Mcp\Schema\Request\ListResourcesRequest;
17+
use Mcp\Schema\Resource;
1818
use Mcp\Schema\Result\ListResourcesResult;
1919
use Mcp\Server\RequestHandler\ListResourcesHandler;
2020
use PHPUnit\Framework\Attributes\TestDox;
@@ -82,7 +82,7 @@ public function testReturnsSecondPageWithCursor(): void
8282
$this->addResourcesToRegistry(10);
8383
$firstPageRequest = $this->createListResourcesRequest();
8484
$firstPageResponse = $this->handler->handle($firstPageRequest);
85-
85+
8686
$secondPageRequest = $this->createListResourcesRequest(cursor: $firstPageResponse->result->nextCursor);
8787

8888
// Act
@@ -107,7 +107,7 @@ public function testReturnsLastPageWithNullCursor(): void
107107
$this->addResourcesToRegistry(5);
108108
$firstPageRequest = $this->createListResourcesRequest();
109109
$firstPageResponse = $this->handler->handle($firstPageRequest);
110-
110+
111111
$secondPageRequest = $this->createListResourcesRequest(cursor: $firstPageResponse->result->nextCursor);
112112

113113
// Act
@@ -192,7 +192,7 @@ public function testMaintainsStableCursorsAcrossCalls(): void
192192
{
193193
// Arrange
194194
$this->addResourcesToRegistry(10);
195-
195+
196196
// Act
197197
$request = $this->createListResourcesRequest();
198198
$response1 = $this->handler->handle($request);
@@ -205,14 +205,14 @@ public function testMaintainsStableCursorsAcrossCalls(): void
205205

206206
private function addResourcesToRegistry(int $count): void
207207
{
208-
for ($i = 0; $i < $count; $i++) {
208+
for ($i = 0; $i < $count; ++$i) {
209209
$resource = new Resource(
210210
uri: "resource://test/resource_$i",
211211
name: "resource_$i",
212212
description: "Test resource $i"
213213
);
214214
// Use a simple callable as handler
215-
$this->registry->registerResource($resource, fn() => null);
215+
$this->registry->registerResource($resource, fn () => null);
216216
}
217217
}
218218

@@ -222,9 +222,9 @@ private function createListResourcesRequest(?string $cursor = null): ListResourc
222222
->setConstructorArgs([$cursor])
223223
->onlyMethods(['getId'])
224224
->getMock();
225-
225+
226226
$mock->method('getId')->willReturn('test-request-id');
227-
227+
228228
return $mock;
229229
}
230-
}
230+
}

tests/Server/RequestHandler/ListToolsHandlerTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
use Mcp\Capability\Registry;
1515
use Mcp\Exception\InvalidCursorException;
16-
use Mcp\Schema\Tool;
1716
use Mcp\Schema\Request\ListToolsRequest;
1817
use Mcp\Schema\Result\ListToolsResult;
18+
use Mcp\Schema\Tool;
1919
use Mcp\Server\RequestHandler\ListToolsHandler;
2020
use PHPUnit\Framework\Attributes\TestDox;
2121
use PHPUnit\Framework\TestCase;
@@ -82,7 +82,7 @@ public function testReturnsSecondPageWithCursor(): void
8282
$this->addToolsToRegistry(10);
8383
$firstPageRequest = $this->createListToolsRequest();
8484
$firstPageResponse = $this->handler->handle($firstPageRequest);
85-
85+
8686
$secondPageRequest = $this->createListToolsRequest(cursor: $firstPageResponse->result->nextCursor);
8787

8888
// Act
@@ -107,7 +107,7 @@ public function testReturnsLastPageWithNullCursor(): void
107107
$this->addToolsToRegistry(5);
108108
$firstPageRequest = $this->createListToolsRequest();
109109
$firstPageResponse = $this->handler->handle($firstPageRequest);
110-
110+
111111
$secondPageRequest = $this->createListToolsRequest(cursor: $firstPageResponse->result->nextCursor);
112112

113113
// Act
@@ -215,7 +215,7 @@ public function testMaintainsStableCursorsAcrossCalls(): void
215215
{
216216
// Arrange
217217
$this->addToolsToRegistry(10);
218-
218+
219219
// Act
220220
$request = $this->createListToolsRequest();
221221
$response1 = $this->handler->handle($request);
@@ -228,15 +228,15 @@ public function testMaintainsStableCursorsAcrossCalls(): void
228228

229229
private function addToolsToRegistry(int $count): void
230230
{
231-
for ($i = 0; $i < $count; $i++) {
231+
for ($i = 0; $i < $count; ++$i) {
232232
$tool = new Tool(
233233
name: "tool_$i",
234234
inputSchema: ['type' => 'object'],
235235
description: "Test tool $i",
236236
annotations: null
237237
);
238238

239-
$this->registry->registerTool($tool, fn() => null);
239+
$this->registry->registerTool($tool, fn () => null);
240240
}
241241
}
242242

@@ -246,9 +246,9 @@ private function createListToolsRequest(?string $cursor = null): ListToolsReques
246246
->setConstructorArgs([$cursor])
247247
->onlyMethods(['getId'])
248248
->getMock();
249-
249+
250250
$mock->method('getId')->willReturn('test-request-id');
251-
251+
252252
return $mock;
253253
}
254-
}
254+
}

0 commit comments

Comments
 (0)