-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Resolve variadic parameters. #883
base: master
Are you sure you want to change the base?
Conversation
Solves #881 |
Any significant feature addition like this requires a new integration test, can you add it? I'm not sure how it behaves with the compiled container. |
@mnapoli You're right. Added test and handling of variadic parameter for |
@@ -58,6 +58,7 @@ | |||
'blank_line_between_import_groups' => false, | |||
'global_namespace_import' => false, | |||
'nullable_type_declaration_for_default_null_value' => false, | |||
'nullable_type_declaration' => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you mean that fixes master?
A bit more clarity would help here 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this change disables the PhpCsFixer nullable_type_declaration
check, preventing the master build from failing. Since PHP 8.4 will deprecate this kind of declaration, I suggest creating a separate Issue/PR to address it. You can then decide whether to standardize on union types or the question mark operator (whichever you think is preferable).
|
||
final class Issue881Test extends BaseContainerTest | ||
{ | ||
public function testContainerWithVariadicParameters(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to DI\Test\IntegrationTest\Definitions\CreateDefinitionTest
and change the signature like the other test methods to merge both tests in 1:
public function testContainerWithVariadicParameters(): void | |
/** | |
* @dataProvider provideContainer | |
*/ | |
public function test_with_variadics(ContainerBuilder $builder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 8854fe6.
|
||
namespace DI\Test\IntegrationTest\Issues\Issue881; | ||
|
||
final class ClassWithVariadicParameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class can be moved to DI\Test\IntegrationTest\Definitions\ObjectDefinition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 8854fe6.
@mnapoli Please don't merge it yet. After digging into issues #619 and #802, and considering Ben's comment I added some edge case tests. Turns out, there are still a few things I need to work through. I'll dive deeper and get this sorted as soon as I can. |
Summary of changes:
|
I can't comment on the code in general as I don't know this codebase at all, but I can confirm that this PR fixes #881 for me. |
ParameterResolver::resolveParameters()
was iterating through the reflection parameters and fetching appropriate values from either named parameters or definition parameters. This meant the number of resolved arguments matched the number of reflection parameters, even if a parameter was variadic. This change adds a check for variadic parameters and adds the rest of the parameters to theargs
array accordingly.