Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
$hasNormalizationClosures = $this->hasNormalizationClosures($node);
$comment = $this->getComment($node);
if ($hasNormalizationClosures) {
$comment .= sprintf(' * @return %s|$this'."\n ", $childClass->getFqcn());
$comment = sprintf(" * @template TValue\n * @param TValue \$value\n%s", $comment);
$comment .= sprintf(' * @return %s|$this'."\n", $childClass->getFqcn());
$comment .= sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n ", $childClass->getFqcn());
}
if ('' !== $comment) {
$comment = "/**\n$comment*/\n";
Expand Down Expand Up @@ -279,7 +281,9 @@ public function NAME(string $VAR, TYPE $VALUE): static

$comment = $this->getComment($node);
if ($hasNormalizationClosures) {
$comment .= sprintf(' * @return %s|$this'."\n ", $childClass->getFqcn());
$comment = sprintf(" * @template TValue\n * @param TValue \$value\n%s", $comment);
$comment .= sprintf(' * @return %s|$this'."\n", $childClass->getFqcn());
$comment .= sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n ", $childClass->getFqcn());
}
if ('' !== $comment) {
$comment = "/**\n$comment*/\n";
Expand Down Expand Up @@ -337,7 +341,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
return $this->PROPERTY[$VAR];
}';
$class->addUse(InvalidConfigurationException::class);
$class->addMethod($methodName, $body, [
$class->addMethod($methodName, str_replace('$value', '$VAR', $body), [
'COMMENT' => $comment, 'PROPERTY' => $property->getName(),
'CLASS' => $childClass->getFqcn(),
'VAR' => '' === $key ? 'key' : $key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class NestedConfig
private $_usedProperties = [];

/**
* @template TValue
* @param TValue $value
* @default {"enabled":null}
* @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig|$this
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig : static)
*/
public function nestedObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig|static
{
Expand All @@ -40,7 +43,10 @@ public function nestedObject(mixed $value = []): \Symfony\Config\ScalarNormalize
}

/**
* @template TValue
* @param TValue $value
* @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|$this
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig : static)
*/
public function nestedListObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public function keyedArray(string $name, mixed $value): static
}

/**
* @template TValue
* @param TValue $value
* @default {"enabled":null}
* @return \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|$this
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\ObjectConfig : static)
*/
public function object(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|static
{
Expand All @@ -71,7 +74,10 @@ public function object(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes
}

/**
* @template TValue
* @param TValue $value
* @return \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|$this
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig : static)
*/
public function listObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|static
{
Expand All @@ -86,7 +92,10 @@ public function listObject(mixed $value = []): \Symfony\Config\ScalarNormalizedT
}

/**
* @template TValue
* @param TValue $value
* @return \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|$this
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig : static)
*/
public function keyedListObject(string $class, mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|static
{
Expand Down