Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Config] Add conditional types to conditional builders #47127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2022
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
[Config] Add conditional types to conditional builders
  • Loading branch information
wouterj committed Jul 30, 2022
commit ce1087e59fe6b8df1d6aaf8bb022b450db03e06b
10 changes: 7 additions & 3 deletions 10 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.