Skip to content

Commit 73e4cc2

Browse files
e0ipsoDDEV User
andauthored
style: apply php-cs-fixer and PHPStan fixes (#289)
* style: apply php-cs-fixer to test files Addresses drift flagged by the default PHP-CS-Fixer config — mostly adds missing `: void` return types on pre-existing test methods. No behavioural changes. * fix: resolve phpstan errors surfaced by qa - Drop the obsolete `Method ::test*() has no return type specified` ignore rule — every test method now declares a return type, so the pattern never matches and phpstan reports it as unmatched. - Remove `?? []` from two reads of `CallToolRequest::$arguments`; the property is typed `array` (non-nullable), so the coalesce is a no-op that phpstan flags. --------- Co-authored-by: DDEV User <nobody@example.com>
1 parent 7af5a34 commit 73e4cc2

16 files changed

Lines changed: 98 additions & 100 deletions

File tree

examples/server/custom-method-handlers/CallToolRequestHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function handle(Request $request, SessionInterface $session): Response|Er
4444
\assert($request instanceof CallToolRequest);
4545

4646
$name = $request->name;
47-
$args = $request->arguments ?? [];
47+
$args = $request->arguments;
4848

4949
if (!isset($this->toolDefinitions[$name])) {
5050
return new Error($request->getId(), Error::METHOD_NOT_FOUND, \sprintf('Tool not found: %s', $name));

phpstan.dist.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ parameters:
1313
- tests/Unit/Capability/Discovery/SchemaGeneratorFixture.php
1414
treatPhpDocTypesAsCertain: false
1515
ignoreErrors:
16-
-
17-
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#"
1816
-
1917
identifier: missingType.iterableValue
2018
path: tests/

src/Server/Handler/Request/CallToolHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function handle(Request $request, SessionInterface $session): Response|Er
5858
\assert($request instanceof CallToolRequest);
5959

6060
$toolName = $request->name;
61-
$arguments = $request->arguments ?? [];
61+
$arguments = $request->arguments;
6262

6363
$this->logger->debug('Executing tool', ['name' => $toolName, 'arguments' => $arguments]);
6464

tests/Unit/Capability/Discovery/DiscoveryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp(): void
3232
$this->discoverer = new Discoverer();
3333
}
3434

35-
public function testDiscoversAllElementTypesCorrectlyFromFixtureFiles()
35+
public function testDiscoversAllElementTypesCorrectlyFromFixtureFiles(): void
3636
{
3737
$discovery = $this->discoverer->discover(__DIR__, ['Fixtures']);
3838

@@ -105,7 +105,7 @@ public function testDiscoversAllElementTypesCorrectlyFromFixtureFiles()
105105
$this->assertEquals([InvocableResourceTemplateFixture::class, '__invoke'], $templates['invokable://user-profile/{userId}']->handler);
106106
}
107107

108-
public function testDoesNotDiscoverElementsFromExcludedDirectories()
108+
public function testDoesNotDiscoverElementsFromExcludedDirectories(): void
109109
{
110110
$discovery = $this->discoverer->discover(__DIR__, ['Fixtures']);
111111
$this->assertArrayHasKey('hidden_subdir_tool', $discovery->getTools());
@@ -114,14 +114,14 @@ public function testDoesNotDiscoverElementsFromExcludedDirectories()
114114
$this->assertArrayNotHasKey('hidden_subdir_tool', $discovery->getTools());
115115
}
116116

117-
public function testHandlesEmptyDirectoriesOrDirectoriesWithNoPhpFiles()
117+
public function testHandlesEmptyDirectoriesOrDirectoriesWithNoPhpFiles(): void
118118
{
119119
$discovery = $this->discoverer->discover(__DIR__, ['EmptyDir']);
120120

121121
$this->assertTrue($discovery->isEmpty());
122122
}
123123

124-
public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNotSetInAttribute()
124+
public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNotSetInAttribute(): void
125125
{
126126
$discovery = $this->discoverer->discover(__DIR__, ['Fixtures']);
127127

@@ -138,7 +138,7 @@ public function testCorrectlyInfersNamesAndDescriptionsFromMethodsOrClassesIfNot
138138
$this->assertEquals('An invokable calculator tool.', $tools['InvokableCalculator']->tool->description);
139139
}
140140

141-
public function testDiscoversEnhancedCompletionProvidersWithValuesAndEnumAttributes()
141+
public function testDiscoversEnhancedCompletionProvidersWithValuesAndEnumAttributes(): void
142142
{
143143
$discovery = $this->discoverer->discover(__DIR__, ['Fixtures']);
144144

tests/Unit/Capability/Discovery/DocBlockParserTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp(): void
2929
$this->parser = new DocBlockParser();
3030
}
3131

32-
public function testGetDescriptionReturnsCorrectDescription()
32+
public function testGetDescriptionReturnsCorrectDescription(): void
3333
{
3434
$method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithSummaryAndDescription');
3535
$docComment = $method->getDocComment() ?: null;
@@ -43,7 +43,7 @@ public function testGetDescriptionReturnsCorrectDescription()
4343
$this->assertEquals('Simple summary line.', $this->parser->getDescription($docBlock2));
4444
}
4545

46-
public function testGetParamTagsReturnsStructuredParamInfo()
46+
public function testGetParamTagsReturnsStructuredParamInfo(): void
4747
{
4848
$method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithParams');
4949
$docComment = $method->getDocComment() ?: null;
@@ -94,7 +94,7 @@ public function testGetParamTagsReturnsStructuredParamInfo()
9494
$this->assertEquals('object param', $this->parser->getParamDescription($params['$param6']));
9595
}
9696

97-
public function testGetTagsByNameReturnsSpecificTags()
97+
public function testGetTagsByNameReturnsSpecificTags(): void
9898
{
9999
$method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithMultipleTags');
100100
$docComment = $method->getDocComment() ?: null;
@@ -116,7 +116,7 @@ public function testGetTagsByNameReturnsSpecificTags()
116116
$this->assertEmpty($nonExistentTags);
117117
}
118118

119-
public function testHandlesMethodWithNoDocblockGracefully()
119+
public function testHandlesMethodWithNoDocblockGracefully(): void
120120
{
121121
$method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithNoDocBlock');
122122
$docComment = $method->getDocComment() ?: null;

tests/Unit/Capability/Discovery/Fixtures/NonDiscoverableClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface MyDiscoverableInterface
2525

2626
trait MyDiscoverableTrait
2727
{
28-
public function traitMethod()
28+
public function traitMethod(): void
2929
{
3030
}
3131
}

tests/Unit/Capability/Discovery/Fixtures/SubDir/HiddenTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class HiddenTool
1717
{
1818
#[McpTool(name: 'hidden_subdir_tool')]
19-
public function run()
19+
public function run(): void
2020
{
2121
}
2222
}

tests/Unit/Capability/Discovery/HandlerResolverTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class HandlerResolverTest extends TestCase
1919
{
20-
public function testResolvesClosuresToReflectionFunction()
20+
public function testResolvesClosuresToReflectionFunction(): void
2121
{
2222
$closure = static function (string $input): string {
2323
return "processed: $input";
@@ -29,7 +29,7 @@ public function testResolvesClosuresToReflectionFunction()
2929
$this->assertEquals('string', $returnType->getName());
3030
}
3131

32-
public function testResolvesValidArrayHandler()
32+
public function testResolvesValidArrayHandler(): void
3333
{
3434
$handler = [ValidHandlerClass::class, 'publicMethod'];
3535
$resolved = HandlerResolver::resolve($handler);
@@ -38,7 +38,7 @@ public function testResolvesValidArrayHandler()
3838
$this->assertEquals(ValidHandlerClass::class, $resolved->getDeclaringClass()->getName());
3939
}
4040

41-
public function testResolvesValidInvokableClassStringHandler()
41+
public function testResolvesValidInvokableClassStringHandler(): void
4242
{
4343
$handler = ValidInvokableClass::class;
4444
$resolved = HandlerResolver::resolve($handler);
@@ -47,7 +47,7 @@ public function testResolvesValidInvokableClassStringHandler()
4747
$this->assertEquals(ValidInvokableClass::class, $resolved->getDeclaringClass()->getName());
4848
}
4949

50-
public function testResolvesStaticMethodsForManualRegistration()
50+
public function testResolvesStaticMethodsForManualRegistration(): void
5151
{
5252
$handler = [ValidHandlerClass::class, 'staticMethod'];
5353
$resolved = HandlerResolver::resolve($handler);
@@ -56,84 +56,84 @@ public function testResolvesStaticMethodsForManualRegistration()
5656
$this->assertTrue($resolved->isStatic());
5757
}
5858

59-
public function testThrowsForInvalidArrayHandlerFormatCount()
59+
public function testThrowsForInvalidArrayHandlerFormatCount(): void
6060
{
6161
$this->expectException(InvalidArgumentException::class);
6262
$this->expectExceptionMessage("Invalid array handler format. Expected [ClassName::class, 'methodName'].");
6363
HandlerResolver::resolve([ValidHandlerClass::class]); /* @phpstan-ignore argument.type */
6464
}
6565

66-
public function testThrowsForInvalidArrayHandlerFormatTypes()
66+
public function testThrowsForInvalidArrayHandlerFormatTypes(): void
6767
{
6868
$this->expectException(InvalidArgumentException::class);
6969
$this->expectExceptionMessage("Invalid array handler format. Expected [ClassName::class, 'methodName'].");
7070
HandlerResolver::resolve([ValidHandlerClass::class, 123]); /* @phpstan-ignore argument.type */
7171
}
7272

73-
public function testThrowsForNonExistentClassInArrayHandler()
73+
public function testThrowsForNonExistentClassInArrayHandler(): void
7474
{
7575
$this->expectException(InvalidArgumentException::class);
7676
$this->expectExceptionMessage('Handler class "NonExistentClass" not found');
7777
HandlerResolver::resolve(['NonExistentClass', 'method']);
7878
}
7979

80-
public function testThrowsForNonExistentMethodInArrayHandler()
80+
public function testThrowsForNonExistentMethodInArrayHandler(): void
8181
{
8282
$this->expectException(InvalidArgumentException::class);
8383
$this->expectExceptionMessage('Handler method "nonExistentMethod" not found in class');
8484
HandlerResolver::resolve([ValidHandlerClass::class, 'nonExistentMethod']);
8585
}
8686

87-
public function testThrowsForNonExistentClassInStringHandler()
87+
public function testThrowsForNonExistentClassInStringHandler(): void
8888
{
8989
$this->expectException(InvalidArgumentException::class);
9090
$this->expectExceptionMessage('Invalid handler format. Expected Closure, [ClassName::class, \'methodName\'] or InvokableClassName::class string.');
9191
HandlerResolver::resolve('NonExistentInvokableClass');
9292
}
9393

94-
public function testThrowsForNonInvokableClassStringHandler()
94+
public function testThrowsForNonInvokableClassStringHandler(): void
9595
{
9696
$this->expectException(InvalidArgumentException::class);
9797
$this->expectExceptionMessage('Invokable handler class "Mcp\Tests\Unit\Capability\Discovery\NonInvokableClass" must have a public "__invoke" method.');
9898
HandlerResolver::resolve(NonInvokableClass::class);
9999
}
100100

101-
public function testThrowsForProtectedMethodHandler()
101+
public function testThrowsForProtectedMethodHandler(): void
102102
{
103103
$this->expectException(InvalidArgumentException::class);
104104
$this->expectExceptionMessage('must be public');
105105
HandlerResolver::resolve([ValidHandlerClass::class, 'protectedMethod']);
106106
}
107107

108-
public function testThrowsForPrivateMethodHandler()
108+
public function testThrowsForPrivateMethodHandler(): void
109109
{
110110
$this->expectException(InvalidArgumentException::class);
111111
$this->expectExceptionMessage('must be public');
112112
HandlerResolver::resolve([ValidHandlerClass::class, 'privateMethod']);
113113
}
114114

115-
public function testThrowsForConstructorAsHandler()
115+
public function testThrowsForConstructorAsHandler(): void
116116
{
117117
$this->expectException(InvalidArgumentException::class);
118118
$this->expectExceptionMessage('cannot be a constructor or destructor');
119119
HandlerResolver::resolve([ValidHandlerClass::class, '__construct']);
120120
}
121121

122-
public function testThrowsForDestructorAsHandler()
122+
public function testThrowsForDestructorAsHandler(): void
123123
{
124124
$this->expectException(InvalidArgumentException::class);
125125
$this->expectExceptionMessage('cannot be a constructor or destructor');
126126
HandlerResolver::resolve([ValidHandlerClass::class, '__destruct']);
127127
}
128128

129-
public function testThrowsForAbstractMethodHandler()
129+
public function testThrowsForAbstractMethodHandler(): void
130130
{
131131
$this->expectException(InvalidArgumentException::class);
132132
$this->expectExceptionMessage('Handler method "Mcp\Tests\Unit\Capability\Discovery\AbstractHandlerClass::abstractMethod" must be abstract.');
133133
HandlerResolver::resolve([AbstractHandlerClass::class, 'abstractMethod']);
134134
}
135135

136-
public function testResolvesClosuresWithDifferentSignatures()
136+
public function testResolvesClosuresWithDifferentSignatures(): void
137137
{
138138
$noParams = static function () {
139139
return 'test';
@@ -152,7 +152,7 @@ public function testResolvesClosuresWithDifferentSignatures()
152152
$this->assertTrue(HandlerResolver::resolve($variadic)->isVariadic());
153153
}
154154

155-
public function testDistinguishesBetweenClosuresAndCallableArrays()
155+
public function testDistinguishesBetweenClosuresAndCallableArrays(): void
156156
{
157157
$closure = static function () {
158158
return 'closure';

0 commit comments

Comments
 (0)