Update codestyle based on updated Symfony rules (#229)

This commit is contained in:
Christopher Hertel 2026-02-01 11:54:31 +01:00 • committed by GitHub
commit c081b90d74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 165 additions and 168 deletions

View file

@ -21,7 +21,7 @@ use Psr\Log\LoggerInterface;
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
set_exception_handler(function (Throwable $t): never {
set_exception_handler(static function (Throwable $t): never {
logger()->critical('Uncaught exception: '.$t->getMessage(), ['exception' => $t]);
exit(1);

View file

@ -27,7 +27,7 @@ $server = Server::builder()
->setCapabilities(new ServerCapabilities(logging: true, tools: true))
->setDiscovery(__DIR__)
->addTool(
function (RequestContext $context, string $dataset): array {
static function (RequestContext $context, string $dataset): array {
$client = $context->getClientGateway();
$client->log(LoggingLevel::Info, sprintf('Running quality checks on dataset "%s"', $dataset));

View file

@ -50,7 +50,7 @@ final class InMemoryTaskRepository implements TaskRepositoryInterface
public function getTasksForUser(string $userId): array
{
return array_values(array_filter($this->tasks, fn ($task) => $task['userId'] === $userId && !$task['completed']));
return array_values(array_filter($this->tasks, static fn ($task) => $task['userId'] === $userId && !$task['completed']));
}
public function getAllTasks(): array

View file

@ -21,7 +21,7 @@ final class SystemStatsService implements StatsServiceInterface
public function getSystemStats(): array
{
$allTasks = $this->taskRepository->getAllTasks();
$completed = \count(array_filter($allTasks, fn ($task) => $task['completed']));
$completed = \count(array_filter($allTasks, static fn ($task) => $task['completed']));
$pending = \count($allTasks) - $completed;
return [

View file

@ -19,6 +19,6 @@ final class UserIdCompletionProvider implements ProviderInterface
public function getCompletions(string $currentValue): array
{
return array_filter(self::AVAILABLE_USER_IDS, fn (string $userId) => str_contains($userId, $currentValue));
return array_filter(self::AVAILABLE_USER_IDS, static fn (string $userId) => str_contains($userId, $currentValue));
}
}

View file

@ -23,7 +23,7 @@ $server = Server::builder()
->setSession(new FileSessionStore(__DIR__.'/sessions'))
->setDiscovery(__DIR__)
->addTool(
function (float $a, float $b, string $operation = 'add'): array {
static function (float $a, float $b, string $operation = 'add'): array {
$result = match ($operation) {
'add' => $a + $b,
'subtract' => $a - $b,
@ -42,7 +42,7 @@ $server = Server::builder()
description: 'Perform basic math operations (add, subtract, multiply, divide)'
)
->addResource(
function (): array {
static function (): array {
$memoryUsage = memory_get_usage(true);
$memoryPeak = memory_get_peak_usage(true);
$uptime = time() - ($_SERVER['REQUEST_TIME_FLOAT'] ?? time());

View file

@ -64,12 +64,12 @@ final class EnvToolHandler
'processed_input_length' => \strlen($input),
'message' => 'Processed in PRODUCTION mode (summary only).',
];
} else {
return [
'mode' => $appMode ?: 'default',
'original_input' => $input,
'message' => 'Processed in default mode (APP_MODE not recognized or not set).',
];
}
return [
'mode' => $appMode ?: 'default',
'original_input' => $input,
'message' => 'Processed in default mode (APP_MODE not recognized or not set).',
];
}
}

View file

@ -267,10 +267,10 @@ final class SchemaShowcaseElements
$processed = array_unique($processed);
break;
case 'filter_short':
$processed = array_filter($processed, fn ($item) => \strlen($item) <= 10);
$processed = array_filter($processed, static fn ($item) => \strlen($item) <= 10);
break;
case 'filter_long':
$processed = array_filter($processed, fn ($item) => \strlen($item) > 10);
$processed = array_filter($processed, static fn ($item) => \strlen($item) > 10);
break;
}

View file

@ -33,7 +33,7 @@ class EnumCompletionProvider implements ProviderInterface
}
$this->values = array_map(
fn ($case) => isset($case->value) && \is_string($case->value) ? $case->value : $case->name,
static fn ($case) => isset($case->value) && \is_string($case->value) ? $case->value : $case->name,
$enumClass::cases()
);
}
@ -46,7 +46,7 @@ class EnumCompletionProvider implements ProviderInterface
return array_values(array_filter(
$this->values,
fn (string $value) => str_starts_with($value, $currentValue)
static fn (string $value) => str_starts_with($value, $currentValue)
));
}
}

View file

@ -32,7 +32,7 @@ class ListCompletionProvider implements ProviderInterface
return array_values(array_filter(
$this->values,
fn (string $value) => str_starts_with($value, $currentValue)
static fn (string $value) => str_starts_with($value, $currentValue)
));
}
}

View file

@ -311,7 +311,7 @@ final class SchemaGenerator implements SchemaGeneratorInterface
// If no items specified by Schema attribute, infer from type
if (!isset($paramSchema['items'])) {
$itemJsonTypes = $this->mapPhpTypeToJsonSchemaType($paramInfo['type_string']);
$nonNullItemTypes = array_filter($itemJsonTypes, fn ($t) => 'null' !== $t);
$nonNullItemTypes = array_filter($itemJsonTypes, static fn ($t) => 'null' !== $t);
if (1 === \count($nonNullItemTypes)) {
$paramSchema['items'] = ['type' => $nonNullItemTypes[0]];
@ -574,7 +574,7 @@ final class SchemaGenerator implements SchemaGeneratorInterface
$types[] = $this->getTypeStringFromReflection($innerType, $innerType->allowsNull());
}
if ($nativeAllowsNull) {
$types = array_filter($types, fn ($t) => 'null' !== strtolower($t));
$types = array_filter($types, static fn ($t) => 'null' !== strtolower($t));
}
$typeString = implode('|', array_unique(array_filter($types)));
} elseif ($type instanceof \ReflectionIntersectionType) {
@ -619,7 +619,7 @@ final class SchemaGenerator implements SchemaGeneratorInterface
// Remove leading backslash from class names, but handle built-ins like 'int' or unions like 'int|string'
if (str_contains($typeString, '\\')) {
$parts = preg_split('/([|&])/', $typeString, -1, \PREG_SPLIT_DELIM_CAPTURE);
$processedParts = array_map(fn ($part) => str_starts_with($part, '\\') ? ltrim($part, '\\') : $part, $parts);
$processedParts = array_map(static fn ($part) => str_starts_with($part, '\\') ? ltrim($part, '\\') : $part, $parts);
$typeString = implode('', $processedParts);
}

View file

@ -145,10 +145,10 @@ class SchemaValidator
}
return $obj;
} else {
// It's a list (sequential array), convert items recursively
return array_map([$this, 'convertDataForValidator'], $data);
}
// It's a list (sequential array), convert items recursively
return array_map([$this, 'convertDataForValidator'], $data);
} elseif (\is_object($data) && $data instanceof \stdClass) {
// Deep copy/convert stdClass objects as well
$obj = new \stdClass();
@ -194,7 +194,7 @@ class SchemaValidator
if (empty($pathComponents)) {
return '/';
}
$escapedComponents = array_map(function ($component) {
$escapedComponents = array_map(static function ($component) {
$componentStr = (string) $component;
return str_replace(['~', '/'], ['~0', '~1'], $componentStr);
@ -215,7 +215,7 @@ class SchemaValidator
switch (strtolower($keyword)) {
case 'required':
$missing = $args['missing'] ?? [];
$formattedMissing = implode(', ', array_map(fn ($p) => "`{$p}`", $missing));
$formattedMissing = implode(', ', array_map(static fn ($p) => "`{$p}`", $missing));
$message = "Missing required properties: {$formattedMissing}.";
break;
case 'type':
@ -236,7 +236,7 @@ class SchemaValidator
if (empty($allowedValues)) {
$message = 'Value does not match the allowed enumeration.';
} else {
$formattedAllowed = array_map(function ($v) { /* ... formatting logic ... */
$formattedAllowed = array_map(static function ($v) { /* ... formatting logic ... */
if (\is_string($v)) {
return '"'.$v.'"';
}
@ -309,7 +309,7 @@ class SchemaValidator
break;
case 'additionalProperties': // Corrected casing
$unexpected = $args['properties'] ?? [];
$formattedUnexpected = implode(', ', array_map(fn ($p) => "`{$p}`", $unexpected));
$formattedUnexpected = implode(', ', array_map(static fn ($p) => "`{$p}`", $unexpected));
$message = "Object contains unexpected additional properties: {$formattedUnexpected}.";
break;
case 'format':
@ -320,7 +320,7 @@ class SchemaValidator
$builtInMessage = $error->message();
if ($builtInMessage && 'The data must match the schema' !== $builtInMessage) {
$placeholders = $args;
$builtInMessage = preg_replace_callback('/\{(\w+)\}/', function ($match) use ($placeholders) {
$builtInMessage = preg_replace_callback('/\{(\w+)\}/', static function ($match) use ($placeholders) {
$key = $match[1];
$value = $placeholders[$key] ?? '{'.$key.'}';

View file

@ -86,7 +86,7 @@ final class ResourceResultFormatter
}
if ($allAreEmbeddedResource && $hasEmbeddedResource) {
return array_map(fn ($item) => $item->resource, $readResult);
return array_map(static fn ($item) => $item->resource, $readResult);
}
if ($hasResourceContents || $hasEmbeddedResource) {

View file

@ -344,10 +344,10 @@ final class Registry implements RegistryInterface
public function getDiscoveryState(): DiscoveryState
{
return new DiscoveryState(
tools: array_filter($this->tools, fn ($tool) => !$tool->isManual),
resources: array_filter($this->resources, fn ($resource) => !$resource->isManual),
prompts: array_filter($this->prompts, fn ($prompt) => !$prompt->isManual),
resourceTemplates: array_filter($this->resourceTemplates, fn ($template) => !$template->isManual),
tools: array_filter($this->tools, static fn ($tool) => !$tool->isManual),
resources: array_filter($this->resources, static fn ($resource) => !$resource->isManual),
prompts: array_filter($this->prompts, static fn ($prompt) => !$prompt->isManual),
resourceTemplates: array_filter($this->resourceTemplates, static fn ($template) => !$template->isManual),
);
}

View file

@ -185,19 +185,17 @@ final class ReferenceHandler implements ReferenceHandlerInterface
}
return $value;
} else {
if (\is_string($argument)) {
foreach ($typeName::cases() as $case) {
if ($case->name === $argument) {
return $case;
}
}
$validNames = array_map(fn ($c) => $c->name, $typeName::cases());
throw new InvalidArgumentException("Invalid value '{$argument}' for unit enum {$typeName}. Expected one of: ".implode(', ', $validNames).'.');
} else {
throw new InvalidArgumentException("Invalid value type '{$argument}' for unit enum {$typeName}. Expected a string matching a case name.");
}
}
if (\is_string($argument)) {
foreach ($typeName::cases() as $case) {
if ($case->name === $argument) {
return $case;
}
}
$validNames = array_map(static fn ($c) => $c->name, $typeName::cases());
throw new InvalidArgumentException("Invalid value '{$argument}' for unit enum {$typeName}. Expected one of: ".implode(', ', $validNames).'.');
}
throw new InvalidArgumentException("Invalid value type '{$argument}' for unit enum {$typeName}. Expected a string matching a case name.");
}
try {

View file

@ -46,7 +46,7 @@ class Annotations implements \JsonSerializable
}
if (null !== $this->audience) {
foreach ($this->audience as $role) {
if (!($role instanceof Role)) {
if (!$role instanceof Role) {
throw new InvalidArgumentException('All audience members must be instances of Role enum.');
}
}
@ -60,7 +60,7 @@ class Annotations implements \JsonSerializable
{
$audience = null;
if (isset($data['audience']) && \is_array($data['audience'])) {
$audience = array_map(fn (string $r) => Role::from($r), $data['audience']);
$audience = array_map(static fn (string $r) => Role::from($r), $data['audience']);
}
return new self(
@ -76,7 +76,7 @@ class Annotations implements \JsonSerializable
{
$data = [];
if (null !== $this->audience) {
$data['audience'] = array_map(fn (Role $r) => $r->value, $this->audience);
$data['audience'] = array_map(static fn (Role $r) => $r->value, $this->audience);
}
if (null !== $this->priority) {
$data['priority'] = $this->priority;

View file

@ -47,7 +47,7 @@ class Prompt implements \JsonSerializable
) {
if (null !== $this->arguments) {
foreach ($this->arguments as $arg) {
if (!($arg instanceof PromptArgument)) {
if (!$arg instanceof PromptArgument) {
throw new InvalidArgumentException('All items in Prompt "arguments" must be PromptArgument instances.');
}
}
@ -64,7 +64,7 @@ class Prompt implements \JsonSerializable
}
$arguments = null;
if (isset($data['arguments']) && \is_array($data['arguments'])) {
$arguments = array_map(fn (array $argData) => PromptArgument::fromArray($argData), $data['arguments']);
$arguments = array_map(static fn (array $argData) => PromptArgument::fromArray($argData), $data['arguments']);
}
if (!empty($data['_meta']) && !\is_array($data['_meta'])) {

View file

@ -50,7 +50,7 @@ class ListPromptsResult implements ResultInterface
}
return new self(
array_map(fn (array $prompt) => Prompt::fromArray($prompt), $data['prompts']),
array_map(static fn (array $prompt) => Prompt::fromArray($prompt), $data['prompts']),
$data['nextCursor'] ?? null
);
}

View file

@ -50,7 +50,7 @@ class ListResourceTemplatesResult implements ResultInterface
}
return new self(
array_map(fn (array $resourceTemplate) => ResourceTemplate::fromArray($resourceTemplate), $data['resourceTemplates']),
array_map(static fn (array $resourceTemplate) => ResourceTemplate::fromArray($resourceTemplate), $data['resourceTemplates']),
$data['nextCursor'] ?? null
);
}

View file

@ -50,7 +50,7 @@ class ListResourcesResult implements ResultInterface
}
return new self(
array_map(fn (array $resource) => ResourceSchema::fromArray($resource), $data['resources']),
array_map(static fn (array $resource) => ResourceSchema::fromArray($resource), $data['resources']),
$data['nextCursor'] ?? null
);
}

Some files were not shown because too many files have changed in this diff Show more