Skip to content

Commit dff5bf0

Browse files
author
larry.sulebalogun
committed
10 - Resolve phpstan issues
1 parent 078be9e commit dff5bf0

File tree

5 files changed

+39
-81
lines changed

5 files changed

+39
-81
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -384,24 +384,6 @@ parameters:
384384
count: 1
385385
path: examples/09-standalone-cli/src/Builder.php
386386

387-
-
388-
message: '#^Access to an undefined property Mcp\\Capability\\Registry\:\:\$referenceHandler\.$#'
389-
identifier: property.notFound
390-
count: 1
391-
path: src/Capability/Registry.php
392-
393-
-
394-
message: '#^Method Mcp\\Capability\\Registry\:\:handleGetPrompt\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
395-
identifier: missingType.iterableValue
396-
count: 1
397-
path: src/Capability/Registry.php
398-
399-
-
400-
message: '#^Return type \(list\<Mcp\\Schema\\Resource\>\) of method Mcp\\Capability\\Registry\:\:getResources\(\) should be compatible with return type \(list\<resource\>\) of method Mcp\\Capability\\Registry\\ReferenceProviderInterface\:\:getResources\(\)$#'
401-
identifier: method.childReturnType
402-
count: 1
403-
path: src/Capability/Registry.php
404-
405387
-
406388
message: '#^Call to an undefined method Mcp\\Capability\\Registry\\ResourceTemplateReference\:\:handle\(\)\.$#'
407389
identifier: method.notFound
@@ -420,30 +402,6 @@ parameters:
420402
count: 1
421403
path: src/Schema/Result/ReadResourceResult.php
422404

423-
-
424-
message: '#^Call to an undefined method Mcp\\Capability\\Registry\\ReferenceProviderInterface\:\:calculateNextCursor\(\)\.$#'
425-
identifier: method.notFound
426-
count: 1
427-
path: src/Server/RequestHandler/ListPromptsHandler.php
428-
429-
-
430-
message: '#^Call to an undefined method Mcp\\Capability\\Registry\\ReferenceProviderInterface\:\:calculateNextCursor\(\)\.$#'
431-
identifier: method.notFound
432-
count: 1
433-
path: src/Server/RequestHandler/ListResourcesHandler.php
434-
435-
-
436-
message: '#^Parameter \#1 \$resources of class Mcp\\Schema\\Result\\ListResourcesResult constructor expects array\<Mcp\\Schema\\Resource\>, list\<resource\> given\.$#'
437-
identifier: argument.type
438-
count: 1
439-
path: src/Server/RequestHandler/ListResourcesHandler.php
440-
441-
-
442-
message: '#^Call to an undefined method Mcp\\Capability\\Registry\\ReferenceProviderInterface\:\:calculateNextCursor\(\)\.$#'
443-
identifier: method.notFound
444-
count: 1
445-
path: src/Server/RequestHandler/ListToolsHandler.php
446-
447405
-
448406
message: '#^Method Mcp\\Server\\ServerBuilder\:\:getCompletionProviders\(\) return type has no value type specified in iterable type array\.$#'
449407
identifier: missingType.iterableValue
@@ -581,27 +539,3 @@ parameters:
581539
identifier: property.onlyWritten
582540
count: 1
583541
path: src/Server/ServerBuilder.php
584-
585-
-
586-
message: '#^Offset ''prompt1'' does not exist on list\<Mcp\\Schema\\Prompt\>\.$#'
587-
identifier: offsetAccess.notFound
588-
count: 1
589-
path: tests/Capability/Registry/RegistryProviderTest.php
590-
591-
-
592-
message: '#^Offset ''test1\://\{id\}'' does not exist on list\<Mcp\\Schema\\ResourceTemplate\>\.$#'
593-
identifier: offsetAccess.notFound
594-
count: 1
595-
path: tests/Capability/Registry/RegistryProviderTest.php
596-
597-
-
598-
message: '#^Offset ''test\://resource1'' does not exist on list\<Mcp\\Schema\\Resource\>\.$#'
599-
identifier: offsetAccess.notFound
600-
count: 1
601-
path: tests/Capability/Registry/RegistryProviderTest.php
602-
603-
-
604-
message: '#^Offset ''tool1'' does not exist on list\<Mcp\\Schema\\Tool\>\.$#'
605-
identifier: offsetAccess.notFound
606-
count: 1
607-
path: tests/Capability/Registry/RegistryProviderTest.php

src/Capability/Registry.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ public function getPrompt(string $name): ?PromptReference
248248
/**
249249
* Gets all registered tools.
250250
*
251-
* @return ReferencePage<Tool>
251+
* @param int|null $limit
252+
* @param string|null $cursor
253+
* @return ReferencePage
252254
*/
253255
public function getTools(?int $limit = null, ?string $cursor = null): ReferencePage
254256
{
@@ -275,7 +277,9 @@ public function getTools(?int $limit = null, ?string $cursor = null): ReferenceP
275277
/**
276278
* Gets all registered resources.
277279
*
278-
* @return ReferencePage<resource>
280+
* @param int|null $limit
281+
* @param string|null $cursor
282+
* @return ReferencePage
279283
*/
280284
public function getResources(?int $limit = null, ?string $cursor = null): ReferencePage
281285
{
@@ -302,7 +306,9 @@ public function getResources(?int $limit = null, ?string $cursor = null): Refere
302306
/**
303307
* Gets all registered prompts.
304308
*
305-
* @return ReferencePage<Prompt>
309+
* @param int|null $limit
310+
* @param string|null $cursor
311+
* @return ReferencePage
306312
*/
307313
public function getPrompts(?int $limit = null, ?string $cursor = null): ReferencePage
308314
{
@@ -329,7 +335,9 @@ public function getPrompts(?int $limit = null, ?string $cursor = null): Referenc
329335
/**
330336
* Gets all registered resource templates.
331337
*
332-
* @return ReferencePage<ResourceTemplate>
338+
* @param int|null $limit
339+
* @param string|null $cursor
340+
* @return ReferencePage
333341
*/
334342
public function getResourceTemplates(?int $limit = null, ?string $cursor = null): ReferencePage
335343
{
@@ -391,11 +399,11 @@ private function calculateNextCursor(int $totalItems, ?string $currentCursor, in
391399
/**
392400
* Helper method to paginate results using cursor-based pagination.
393401
*
394-
* @param list<mixed> $items The full array of items to paginate
395-
* @param int $limit Maximum number of items to return
396-
* @param string|null $cursor Base64 encoded offset position
402+
* @param array<int|string, mixed> $items The full array of items to paginate The full array of items to paginate
403+
* @param int $limit Maximum number of items to return
404+
* @param string|null $cursor Base64 encoded offset position
397405
*
398-
* @return list<mixed> Paginated results
406+
* @return array<int|string, mixed> Paginated results
399407
*
400408
* @throws InvalidCursorException When cursor is invalid (MCP error code -32602)
401409
*/

src/Capability/Registry/ReferenceProviderInterface.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,36 @@ public function getPrompt(string $name): ?PromptReference;
4747
/**
4848
* Gets all registered tools.
4949
*
50-
* @return ReferencePage<Tool>
50+
* @param int|null $limit
51+
* @param string|null $cursor
52+
* @return ReferencePage
5153
*/
5254
public function getTools(?int $limit = null, ?string $cursor = null): ReferencePage;
5355

5456
/**
5557
* Gets all registered resources.
5658
*
57-
* @return ReferencePage<resource>
59+
* @param int|null $limit
60+
* @param string|null $cursor
61+
* @return ReferencePage
5862
*/
5963
public function getResources(?int $limit = null, ?string $cursor = null): ReferencePage;
6064

6165
/**
6266
* Gets all registered prompts.
6367
*
64-
* @return ReferencePage<Prompt>
68+
* @param int|null $limit
69+
* @param string|null $cursor
70+
* @return ReferencePage
6571
*/
6672
public function getPrompts(?int $limit = null, ?string $cursor = null): ReferencePage;
6773

6874
/**
6975
* Gets all registered resource templates.
7076
*
71-
* @return ReferencePage<ResourceTemplate>
77+
* @param int|null $limit
78+
* @param string|null $cursor
79+
* @return ReferencePage
7280
*/
7381
public function getResourceTemplates(?int $limit = null, ?string $cursor = null): ReferencePage;
7482

src/Server/RequestHandler/ReferencePage.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111

1212
namespace Mcp\Server\RequestHandler;
1313

14+
/**
15+
* @implements \ArrayAccess<int|string, mixed>
16+
*/
1417
final class ReferencePage implements \Countable, \ArrayAccess
1518
{
19+
/**
20+
* @param array<int|string, mixed> $references Items can be Tool, Prompt, ResourceTemplate, or Resource
21+
* @param string|null $nextCursor
22+
*/
1623
public function __construct(
1724
public readonly array $references,
1825
public readonly ?string $nextCursor,
@@ -36,11 +43,11 @@ public function offsetGet(mixed $offset): mixed
3643

3744
public function offsetSet(mixed $offset, mixed $value): void
3845
{
39-
// TODO: Implement offsetSet() method.
46+
return;
4047
}
4148

4249
public function offsetUnset(mixed $offset): void
4350
{
44-
// TODO: Implement offsetUnset() method.
51+
return;
4552
}
4653
}

tests/Capability/Discovery/DiscoveryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public function testDoesNotDiscoverElementsFromExcludedDirectories()
135135
public function testHandlesEmptyDirectoriesOrDirectoriesWithNoPhpFiles()
136136
{
137137
$this->discoverer->discover(__DIR__, ['EmptyDir']);
138-
$this->assertEmpty($this->registry->getTools());
138+
$tools = $this->registry->getTools();
139+
$this->assertEmpty($tools->references);
139140
}
140141

141142
public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNotSetInAttribute()

0 commit comments

Comments
 (0)