Skip to content

[Config] Fix generating PHP config for keyed list of scalars #60316

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

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from

Conversation

robotomarvin
Copy link

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60282
License MIT

Fixes generated PHP config for keyed objects with array of scalars. Also enhances conditional returns for PHPStan compatibility.

Comment on lines +35 to +37
$keyedListScalarConfig = new KeyedListScalarConfig();
$keyedListScalarConfig->list(['one', 'two']);
$config->keyedListScalar('Foo\\Foo', $keyedListScalarConfig);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really how configuration classes are meant to be used. They should never be manually instantiated.

The main issue I see is that in some cases, $value can be multiple types, for example, MessengerConfig::transport:

public function transport(string $name, string|array $value = []): \Symfony\Config\Framework\Messenger\TransportConfig|static
{
    // ...
}

In other cases, it can only be an array. The proper fix would be to avoid including the if (!\is_array($value)) { check when the type is strictly an array.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got it, maybe then __construct of generated classes should be marked as @internal right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, not sure about that one 🤔

@@ -284,15 +284,16 @@ public function NAME(string $VAR, TYPE $VALUE): static
if ($hasNormalizationClosures) {
$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());
$comment .= sprintf(' * @psalm-return (TValue is array ? %s : static)'."\n", $childClass->getFqcn());
$comment .= sprintf(' * @phpstan-return ($value is array ? %s : $this)'."\n ", $childClass->getFqcn());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvements like this don't qualify as bug fixes, so this should be a separate PR for 7.3 (or more likely 7.4, since 7.3 is now in feature freeze).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was searching for for some guide lines on what qualifies as bug, but I'm not sure, this seem to me like a bug, currently it's not possible to use some php configs with strict PHPStan, that said, I'm going to change the target to 7.3 or 7.4 (when branch is available)
Outside of target branch, do you think this is acceptable fix/improvement? Or do I need to do it in any other way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants