Skip to content

Commit a28dc2a

Browse files
committed
phpstan fix
1 parent b632363 commit a28dc2a

File tree

11 files changed

+36
-177
lines changed

11 files changed

+36
-177
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -402,96 +402,6 @@ parameters:
402402
count: 1
403403
path: examples/09-standalone-cli/src/Builder.php
404404

405-
-
406-
message: '#^Call to protected method formatResult\(\) of class Mcp\\Capability\\Registry\\ResourceReference\.$#'
407-
identifier: method.protected
408-
count: 1
409-
path: src/Capability/Registry.php
410-
411-
-
412-
message: '#^Cannot import type alias CallableArray\: type alias does not exist in Mcp\\Capability\\Registry\\ElementReference\.$#'
413-
identifier: typeAlias.notFound
414-
count: 1
415-
path: src/Capability/Registry.php
416-
417-
-
418-
message: '#^Method Mcp\\Capability\\Registry\:\:handleCallTool\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
419-
identifier: missingType.iterableValue
420-
count: 1
421-
path: src/Capability/Registry.php
422-
423-
-
424-
message: '#^Method Mcp\\Capability\\Registry\:\:handleCallTool\(\) return type has no value type specified in iterable type array\.$#'
425-
identifier: missingType.iterableValue
426-
count: 1
427-
path: src/Capability/Registry.php
428-
429-
-
430-
message: '#^Method Mcp\\Capability\\Registry\:\:handleGetPrompt\(\) has parameter \$arguments with no value type specified in iterable type array\.$#'
431-
identifier: missingType.iterableValue
432-
count: 1
433-
path: src/Capability/Registry.php
434-
435-
-
436-
message: '#^Method Mcp\\Capability\\Registry\:\:registerPrompt\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
437-
identifier: missingType.iterableValue
438-
count: 1
439-
path: src/Capability/Registry.php
440-
441-
-
442-
message: '#^Method Mcp\\Capability\\Registry\:\:registerResource\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
443-
identifier: missingType.iterableValue
444-
count: 1
445-
path: src/Capability/Registry.php
446-
447-
-
448-
message: '#^Method Mcp\\Capability\\Registry\:\:registerResourceTemplate\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
449-
identifier: missingType.iterableValue
450-
count: 1
451-
path: src/Capability/Registry.php
452-
453-
-
454-
message: '#^Method Mcp\\Capability\\Registry\:\:registerTool\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
455-
identifier: missingType.iterableValue
456-
count: 1
457-
path: src/Capability/Registry.php
458-
459-
-
460-
message: '#^PHPDoc tag @param for parameter \$handler with type \(callable\)\|Mcp\\Capability\\CallableArray\|string is not subtype of native type array\|\(callable\)\|string\.$#'
461-
identifier: parameter.phpDocType
462-
count: 4
463-
path: src/Capability/Registry.php
464-
465-
-
466-
message: '#^Parameter \$handler of method Mcp\\Capability\\Registry\:\:registerPrompt\(\) has invalid type Mcp\\Capability\\CallableArray\.$#'
467-
identifier: class.notFound
468-
count: 1
469-
path: src/Capability/Registry.php
470-
471-
-
472-
message: '#^Parameter \$handler of method Mcp\\Capability\\Registry\:\:registerResource\(\) has invalid type Mcp\\Capability\\CallableArray\.$#'
473-
identifier: class.notFound
474-
count: 1
475-
path: src/Capability/Registry.php
476-
477-
-
478-
message: '#^Parameter \$handler of method Mcp\\Capability\\Registry\:\:registerResourceTemplate\(\) has invalid type Mcp\\Capability\\CallableArray\.$#'
479-
identifier: class.notFound
480-
count: 1
481-
path: src/Capability/Registry.php
482-
483-
-
484-
message: '#^Parameter \$handler of method Mcp\\Capability\\Registry\:\:registerTool\(\) has invalid type Mcp\\Capability\\CallableArray\.$#'
485-
identifier: class.notFound
486-
count: 1
487-
path: src/Capability/Registry.php
488-
489-
-
490-
message: '#^Call to an undefined method Mcp\\Capability\\Registry\\ResourceTemplateReference\:\:handle\(\)\.$#'
491-
identifier: method.notFound
492-
count: 1
493-
path: src/Capability/Registry/ResourceTemplateReference.php
494-
495405
-
496406
message: '#^PHPDoc tag @return with type array is incompatible with native type object\.$#'
497407
identifier: return.phpDocType
@@ -504,30 +414,6 @@ parameters:
504414
count: 1
505415
path: src/Schema/Result/ReadResourceResult.php
506416

507-
-
508-
message: '#^Method Mcp\\Capability\\Registry\:\:getPrompts\(\) invoked with 2 parameters, 0 required\.$#'
509-
identifier: arguments.count
510-
count: 1
511-
path: src/Server/RequestHandler/ListPromptsHandler.php
512-
513-
-
514-
message: '#^Result of && is always false\.$#'
515-
identifier: booleanAnd.alwaysFalse
516-
count: 1
517-
path: src/Server/RequestHandler/ListPromptsHandler.php
518-
519-
-
520-
message: '#^Strict comparison using \!\=\= between null and null will always evaluate to false\.$#'
521-
identifier: notIdentical.alwaysFalse
522-
count: 1
523-
path: src/Server/RequestHandler/ListPromptsHandler.php
524-
525-
-
526-
message: '#^Method Mcp\\Capability\\Registry\:\:getResources\(\) invoked with 2 parameters, 0 required\.$#'
527-
identifier: arguments.count
528-
count: 1
529-
path: src/Server/RequestHandler/ListResourcesHandler.php
530-
531417
-
532418
message: '#^Result of && is always false\.$#'
533419
identifier: booleanAnd.alwaysFalse
@@ -540,12 +426,6 @@ parameters:
540426
count: 1
541427
path: src/Server/RequestHandler/ListResourcesHandler.php
542428

543-
-
544-
message: '#^Method Mcp\\Capability\\Registry\:\:getTools\(\) invoked with 2 parameters, 0 required\.$#'
545-
identifier: arguments.count
546-
count: 1
547-
path: src/Server/RequestHandler/ListToolsHandler.php
548-
549429
-
550430
message: '#^Result of && is always false\.$#'
551431
identifier: booleanAnd.alwaysFalse

src/Capability/Registry.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Mcp\Capability;
1313

14-
use Mcp\Capability\Registry\ElementReference;
1514
use Mcp\Capability\Registry\PromptReference;
1615
use Mcp\Capability\Registry\ReferenceProviderInterface;
1716
use Mcp\Capability\Registry\ReferenceRegistryInterface;
@@ -27,8 +26,6 @@
2726
use Psr\Log\NullLogger;
2827

2928
/**
30-
* @phpstan-import-type CallableArray from ElementReference
31-
*
3229
* Registry implementation that manages MCP element registration and access.
3330
* Implements both ReferenceProvider (for access) and ReferenceRegistry (for registration)
3431
* following the Interface Segregation Principle.
@@ -82,9 +79,6 @@ public function getCapabilities(): ServerCapabilities
8279
);
8380
}
8481

85-
/**
86-
* @param callable|CallableArray|string $handler
87-
*/
8882
public function registerTool(Tool $tool, callable|array|string $handler, bool $isManual = false): void
8983
{
9084
$toolName = $tool->name;
@@ -101,9 +95,6 @@ public function registerTool(Tool $tool, callable|array|string $handler, bool $i
10195
$this->tools[$toolName] = new ToolReference($tool, $handler, $isManual);
10296
}
10397

104-
/**
105-
* @param callable|CallableArray|string $handler
106-
*/
10798
public function registerResource(Resource $resource, callable|array|string $handler, bool $isManual = false): void
10899
{
109100
$uri = $resource->uri;
@@ -120,10 +111,6 @@ public function registerResource(Resource $resource, callable|array|string $hand
120111
$this->resources[$uri] = new ResourceReference($resource, $handler, $isManual);
121112
}
122113

123-
/**
124-
* @param callable|CallableArray|string $handler
125-
* @param array<string, class-string|object> $completionProviders
126-
*/
127114
public function registerResourceTemplate(
128115
ResourceTemplate $template,
129116
callable|array|string $handler,
@@ -149,10 +136,6 @@ public function registerResourceTemplate(
149136
);
150137
}
151138

152-
/**
153-
* @param callable|CallableArray|string $handler
154-
* @param array<string, class-string|object> $completionProviders
155-
*/
156139
public function registerPrompt(
157140
Prompt $prompt,
158141
callable|array|string $handler,
@@ -173,9 +156,6 @@ public function registerPrompt(
173156
$this->prompts[$promptName] = new PromptReference($prompt, $handler, $isManual, $completionProviders);
174157
}
175158

176-
/**
177-
* Clear discovered elements from registry.
178-
*/
179159
public function clear(): void
180160
{
181161
$clearCount = 0;
@@ -249,42 +229,27 @@ public function getPrompt(string $name): ?PromptReference
249229
return $this->prompts[$name] ?? null;
250230
}
251231

252-
/**
253-
* @return array<string, Tool>
254-
*/
255232
public function getTools(): array
256233
{
257234
return array_map(fn (ToolReference $tool) => $tool->tool, $this->tools);
258235
}
259236

260-
/**
261-
* @return array<string, resource>
262-
*/
263237
public function getResources(): array
264238
{
265239
return array_map(fn (ResourceReference $resource) => $resource->schema, $this->resources);
266240
}
267241

268-
/**
269-
* @return array<string, Prompt>
270-
*/
271242
public function getPrompts(): array
272243
{
273244
return array_map(fn (PromptReference $prompt) => $prompt->prompt, $this->prompts);
274245
}
275246

276-
/**
277-
* @return array<string, ResourceTemplate>
278-
*/
279247
public function getResourceTemplates(): array
280248
{
281249
return array_map(fn (ResourceTemplateReference $template) => $template->resourceTemplate,
282250
$this->resourceTemplates);
283251
}
284252

285-
/**
286-
* Checks if any elements (manual or discovered) are currently registered.
287-
*/
288253
public function hasElements(): bool
289254
{
290255
return !empty($this->tools)

src/Capability/Registry/ReferenceRegistryInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Mcp\Schema\Tool;
1919

2020
/**
21-
* @phpstan-import-type CallableArray from ElementReference
21+
* @phpstan-import-type Handler from ElementReference
2222
*
2323
* Interface for registering MCP elements.
2424
* Separates the concern of registering elements from accessing them.
@@ -35,21 +35,21 @@ public function getCapabilities(): ServerCapabilities;
3535
/**
3636
* Registers a tool with its handler.
3737
*
38-
* @param callable|CallableArray|string $handler
38+
* @param Handler $handler
3939
*/
4040
public function registerTool(Tool $tool, callable|array|string $handler, bool $isManual = false): void;
4141

4242
/**
4343
* Registers a resource with its handler.
4444
*
45-
* @param callable|CallableArray|string $handler
45+
* @param Handler $handler
4646
*/
4747
public function registerResource(Resource $resource, callable|array|string $handler, bool $isManual = false): void;
4848

4949
/**
5050
* Registers a resource template with its handler and completion providers.
5151
*
52-
* @param callable|CallableArray|string $handler
52+
* @param Handler $handler
5353
* @param array<string, class-string|object> $completionProviders
5454
*/
5555
public function registerResourceTemplate(
@@ -62,7 +62,7 @@ public function registerResourceTemplate(
6262
/**
6363
* Registers a prompt with its handler and completion providers.
6464
*
65-
* @param callable|CallableArray|string $handler
65+
* @param Handler $handler
6666
* @param array<string, class-string|object> $completionProviders
6767
*/
6868
public function registerPrompt(

src/Capability/Registry/ResourceTemplateReference.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function __construct(
5555
}
5656

5757
/**
58-
* Gets the resource template.
58+
* @deprecated
59+
* Gets the resource template
5960
*
6061
* @return array<int, ResourceContents> array of ResourceContents objects
6162
*/

src/Capability/Tool/DefaultToolExecutor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
use Mcp\Capability\Registry\ReferenceProviderInterface;
1616
use Mcp\Exception\ToolExecutionException;
1717
use Mcp\Exception\ToolNotFoundException;
18+
use Mcp\Schema\Content\AudioContent;
19+
use Mcp\Schema\Content\EmbeddedResource;
20+
use Mcp\Schema\Content\ImageContent;
21+
use Mcp\Schema\Content\TextContent;
1822
use Mcp\Schema\Request\CallToolRequest;
1923
use Mcp\Schema\Result\CallToolResult;
2024
use Psr\Log\LoggerInterface;
@@ -55,6 +59,7 @@ public function call(CallToolRequest $request): CallToolResult
5559

5660
try {
5761
$result = $this->referenceHandler->handle($toolReference, $arguments);
62+
/** @var TextContent[]|ImageContent[]|EmbeddedResource[]|AudioContent[] $formattedResult */
5863
$formattedResult = $toolReference->formatResult($result);
5964

6065
$this->logger->debug('Tool executed successfully', [

src/Schema/ServerCapabilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function withEvents(): self
6666
* completions?: mixed,
6767
* prompts?: array{listChanged?: bool}|object,
6868
* resources?: array{listChanged?: bool, subscribe?: bool}|object,
69-
* tools?: object,
69+
* tools?: object|array{listChanged?: bool},
7070
* experimental?: array<string, mixed>,
7171
* } $data
7272
*/

tests/Capability/Prompt/DefaultPromptGetterTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Mcp\Tests\Capability\Prompt;
1313

14+
use Mcp\Capability\Prompt\Completion\EnumCompletionProvider;
1415
use Mcp\Capability\Prompt\DefaultPromptGetter;
1516
use Mcp\Capability\Registry\PromptReference;
1617
use Mcp\Capability\Registry\ReferenceHandlerInterface;
@@ -23,13 +24,14 @@
2324
use Mcp\Schema\Prompt;
2425
use Mcp\Schema\Request\GetPromptRequest;
2526
use Mcp\Schema\Result\GetPromptResult;
27+
use PHPUnit\Framework\MockObject\MockObject;
2628
use PHPUnit\Framework\TestCase;
2729

2830
class DefaultPromptGetterTest extends TestCase
2931
{
3032
private DefaultPromptGetter $promptGetter;
31-
private ReferenceProviderInterface $referenceProvider;
32-
private ReferenceHandlerInterface $referenceHandler;
33+
private ReferenceProviderInterface|MockObject $referenceProvider;
34+
private ReferenceHandlerInterface|MockObject $referenceHandler;
3335

3436
protected function setUp(): void
3537
{
@@ -393,7 +395,7 @@ public function testGetWithPromptReferenceHavingCompletionProviders(): void
393395
{
394396
$request = new GetPromptRequest('completion_prompt', ['param' => 'value']);
395397
$prompt = $this->createValidPrompt('completion_prompt');
396-
$completionProviders = ['param' => 'SomeCompletionProvider'];
398+
$completionProviders = ['param' => EnumCompletionProvider::class];
397399
$promptReference = new PromptReference(
398400
$prompt,
399401
fn () => 'Completion content',

0 commit comments

Comments
 (0)