Skip to content

Commit 0add43d

Browse files
committed
Apply php-cs-fixer to satisfy QA
1 parent c61a756 commit 0add43d

12 files changed

Lines changed: 109 additions & 121 deletions

File tree

examples/server/oauth-keycloak/McpElements.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the official PHP MCP SDK.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
namespace Mcp\Example\Server\OAuthKeycloak;
1516

1617
use Mcp\Capability\Attribute\McpPrompt;
@@ -62,7 +63,7 @@ public function callProtectedApi(
6263

6364
return [
6465
'status' => 'success',
65-
'message' => sprintf('Simulated %s request to %s', $method, $endpoint),
66+
'message' => \sprintf('Simulated %s request to %s', $method, $endpoint),
6667
'simulated_response' => [
6768
'data' => 'This is simulated data from the protected API',
6869
'timestamp' => date('c'),
@@ -84,7 +85,7 @@ public function getServerStatus(): array
8485
return [
8586
'status' => 'healthy',
8687
'timestamp' => date('c'),
87-
'php_version' => PHP_VERSION,
88+
'php_version' => \PHP_VERSION,
8889
'memory_usage_mb' => round(memory_get_usage(true) / 1024 / 1024, 2),
8990
'protected' => true,
9091
];
@@ -100,10 +101,10 @@ public function getServerStatus(): array
100101
public function greeting(string $style = 'formal'): string
101102
{
102103
return match ($style) {
103-
'casual' => "Hey there! Welcome to the protected MCP server!",
104-
'formal' => "Good day. Welcome to the OAuth-protected MCP server.",
105-
'friendly' => "Hello! Great to have you here!",
106-
default => "Welcome to the MCP server!",
104+
'casual' => 'Hey there! Welcome to the protected MCP server!',
105+
'formal' => 'Good day. Welcome to the OAuth-protected MCP server.',
106+
'friendly' => 'Hello! Great to have you here!',
107+
default => 'Welcome to the MCP server!',
107108
};
108109
}
109110
}

examples/server/oauth-keycloak/server.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the official PHP MCP SDK.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
require_once dirname(__DIR__).'/bootstrap.php';
1516

1617
use Http\Discovery\Psr17Factory;

examples/server/oauth-microsoft/McpElements.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the official PHP MCP SDK.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
namespace Mcp\Example\Server\OAuthMicrosoft;
1516

1617
use Mcp\Capability\Attribute\McpPrompt;
@@ -78,7 +79,7 @@ public function listEmails(int $count = 5): array
7879
{
7980
return [
8081
'note' => 'Simulated data. Implement Graph API call with Mail.Read scope for real emails.',
81-
'emails' => array_map(fn ($i) => [
82+
'emails' => array_map(static fn ($i) => [
8283
'id' => 'msg_'.uniqid(),
8384
'subject' => "Sample Email #{$i}",
8485
'from' => "sender{$i}@example.com",
@@ -102,7 +103,7 @@ public function getServerStatus(): array
102103
'status' => 'healthy',
103104
'timestamp' => date('c'),
104105
'auth_provider' => 'Microsoft Entra ID',
105-
'php_version' => PHP_VERSION,
106+
'php_version' => \PHP_VERSION,
106107
'memory_usage_mb' => round(memory_get_usage(true) / 1024 / 1024, 2),
107108
];
108109
}

examples/server/oauth-microsoft/server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
4+
declare(strict_types=1);
5+
36
/*
47
* This file is part of the official PHP MCP SDK.
58
*
@@ -9,8 +12,6 @@
912
* file that was distributed with this source code.
1013
*/
1114

12-
declare(strict_types=1);
13-
1415
require_once dirname(__DIR__).'/bootstrap.php';
1516

1617
use Http\Discovery\Psr17Factory;
@@ -22,7 +23,6 @@
2223
use Mcp\Server\Transport\Middleware\OAuthProxyMiddleware;
2324
use Mcp\Server\Transport\Middleware\ProtectedResourceMetadata;
2425
use Mcp\Server\Transport\StreamableHttpTransport;
25-
use Psr\Log\AbstractLogger;
2626

2727
// Configuration from environment
2828
$tenantId = getenv('AZURE_TENANT_ID') ?: throw new RuntimeException('AZURE_TENANT_ID environment variable is required');

src/Server/Transport/Middleware/AuthorizationMiddleware.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ final class AuthorizationMiddleware implements MiddlewareInterface
4444
private $scopeProvider;
4545

4646
/**
47-
* @param ProtectedResourceMetadata $metadata The protected resource metadata to serve
48-
* @param AuthorizationTokenValidatorInterface $validator Token validator implementation
49-
* @param ResponseFactoryInterface|null $responseFactory PSR-17 response factory (auto-discovered if null)
50-
* @param StreamFactoryInterface|null $streamFactory PSR-17 stream factory (auto-discovered if null)
51-
* @param list<string> $metadataPaths Paths where metadata should be served (e.g., ["/.well-known/oauth-protected-resource"])
52-
* @param string|null $resourceMetadataUrl Explicit URL for the resource_metadata in WWW-Authenticate
53-
* @param callable(ServerRequestInterface): list<string>|null $scopeProvider Optional callback to determine required scopes per request
47+
* @param ProtectedResourceMetadata $metadata The protected resource metadata to serve
48+
* @param AuthorizationTokenValidatorInterface $validator Token validator implementation
49+
* @param ResponseFactoryInterface|null $responseFactory PSR-17 response factory (auto-discovered if null)
50+
* @param StreamFactoryInterface|null $streamFactory PSR-17 stream factory (auto-discovered if null)
51+
* @param list<string> $metadataPaths Paths where metadata should be served (e.g., ["/.well-known/oauth-protected-resource"])
52+
* @param string|null $resourceMetadataUrl Explicit URL for the resource_metadata in WWW-Authenticate
53+
* @param callable(ServerRequestInterface): list<string>|null $scopeProvider Optional callback to determine required scopes per request
5454
*/
5555
public function __construct(
5656
private ProtectedResourceMetadata $metadata,
@@ -109,7 +109,7 @@ private function isMetadataRequest(ServerRequestInterface $request): bool
109109
return false;
110110
}
111111

112-
return in_array($request->getUri()->getPath(), $this->metadataPaths, true);
112+
return \in_array($request->getUri()->getPath(), $this->metadataPaths, true);
113113
}
114114

115115
private function buildErrorResponse(ServerRequestInterface $request, AuthorizationResult $result): ResponseInterface
@@ -130,27 +130,27 @@ private function buildAuthenticateHeader(ServerRequestInterface $request, Author
130130

131131
$resourceMetadataUrl = $this->resolveResourceMetadataUrl($request);
132132
if (null !== $resourceMetadataUrl) {
133-
$parts[] = 'resource_metadata="' . $this->escapeHeaderValue($resourceMetadataUrl) . '"';
133+
$parts[] = 'resource_metadata="'.$this->escapeHeaderValue($resourceMetadataUrl).'"';
134134
}
135135

136136
$scopes = $this->resolveScopes($request, $result);
137137
if (null !== $scopes) {
138-
$parts[] = 'scope="' . $this->escapeHeaderValue(implode(' ', $scopes)) . '"';
138+
$parts[] = 'scope="'.$this->escapeHeaderValue(implode(' ', $scopes)).'"';
139139
}
140140

141141
if (null !== $result->getError()) {
142-
$parts[] = 'error="' . $this->escapeHeaderValue($result->getError()) . '"';
142+
$parts[] = 'error="'.$this->escapeHeaderValue($result->getError()).'"';
143143
}
144144

145145
if (null !== $result->getErrorDescription()) {
146-
$parts[] = 'error_description="' . $this->escapeHeaderValue($result->getErrorDescription()) . '"';
146+
$parts[] = 'error_description="'.$this->escapeHeaderValue($result->getErrorDescription()).'"';
147147
}
148148

149149
if ([] === $parts) {
150150
return 'Bearer';
151151
}
152152

153-
return 'Bearer ' . implode(', ', $parts);
153+
return 'Bearer '.implode(', ', $parts);
154154
}
155155

156156
/**
@@ -210,7 +210,7 @@ private function resolveResourceMetadataUrl(ServerRequestInterface $request): ?s
210210
return null;
211211
}
212212

213-
return $scheme . '://' . $authority . $this->metadataPaths[0];
213+
return $scheme.'://'.$authority.$this->metadataPaths[0];
214214
}
215215

216216
/**
@@ -240,7 +240,7 @@ private function normalizePaths(array $paths): array
240240
continue;
241241
}
242242
if ('/' !== $path[0]) {
243-
$path = '/' . $path;
243+
$path = '/'.$path;
244244
}
245245
$normalized[] = $path;
246246
}

src/Server/Transport/Middleware/AuthorizationResult.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
final class AuthorizationResult
2626
{
2727
/**
28-
* @param list<string>|null $scopes Scopes to include in WWW-Authenticate challenge
28+
* @param list<string>|null $scopes Scopes to include in WWW-Authenticate challenge
2929
* @param array<string, mixed> $attributes Attributes to attach to the request on success
3030
*/
3131
private function __construct(
@@ -53,16 +53,15 @@ public static function allow(array $attributes = []): self
5353
*
5454
* Use when no valid credentials are provided or the token is invalid.
5555
*
56-
* @param string|null $error OAuth error code (e.g., "invalid_token")
57-
* @param string|null $errorDescription Human-readable error description
58-
* @param list<string>|null $scopes Required scopes to include in challenge
56+
* @param string|null $error OAuth error code (e.g., "invalid_token")
57+
* @param string|null $errorDescription Human-readable error description
58+
* @param list<string>|null $scopes Required scopes to include in challenge
5959
*/
6060
public static function unauthorized(
6161
?string $error = null,
6262
?string $errorDescription = null,
6363
?array $scopes = null,
64-
): self
65-
{
64+
): self {
6665
return new self(false, 401, $error, $errorDescription, $scopes, []);
6766
}
6867

@@ -71,16 +70,15 @@ public static function unauthorized(
7170
*
7271
* Use when the token is valid but lacks required permissions/scopes.
7372
*
74-
* @param string|null $error OAuth error code (defaults to "insufficient_scope")
75-
* @param string|null $errorDescription Human-readable error description
76-
* @param list<string>|null $scopes Required scopes to include in challenge
73+
* @param string|null $error OAuth error code (defaults to "insufficient_scope")
74+
* @param string|null $errorDescription Human-readable error description
75+
* @param list<string>|null $scopes Required scopes to include in challenge
7776
*/
7877
public static function forbidden(
7978
?string $error = 'insufficient_scope',
8079
?string $errorDescription = null,
8180
?array $scopes = null,
82-
): self
83-
{
81+
): self {
8482
return new self(false, 403, $error ?? 'insufficient_scope', $errorDescription, $scopes, []);
8583
}
8684

@@ -89,14 +87,13 @@ public static function forbidden(
8987
*
9088
* Use when the Authorization header is malformed.
9189
*
92-
* @param string|null $error OAuth error code (defaults to "invalid_request")
90+
* @param string|null $error OAuth error code (defaults to "invalid_request")
9391
* @param string|null $errorDescription Human-readable error description
9492
*/
9593
public static function badRequest(
9694
?string $error = 'invalid_request',
9795
?string $errorDescription = null,
98-
): self
99-
{
96+
): self {
10097
return new self(false, 400, $error ?? 'invalid_request', $errorDescription, null, []);
10198
}
10299

src/Server/Transport/Middleware/AuthorizationTokenValidatorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ interface AuthorizationTokenValidatorInterface
2626
/**
2727
* Validates an access token extracted from the Authorization header.
2828
*
29-
* @param ServerRequestInterface $request The incoming HTTP request
30-
* @param string $accessToken The bearer token (without "Bearer " prefix)
29+
* @param ServerRequestInterface $request The incoming HTTP request
30+
* @param string $accessToken The bearer token (without "Bearer " prefix)
3131
*
3232
* @return AuthorizationResult The result of the validation
3333
*/

0 commit comments

Comments
 (0)