Update codestyle based on updated Symfony rules (#229)
This commit is contained in:
parent
e485fde727
commit
c081b90d74
7 changed files with 165 additions and 168 deletions
|
|
@ -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)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.'}';
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue