Skip to content
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

Add failing test for GetParameterToConstructorInjectionRector #275

Conversation

mttsch
Copy link
Contributor

@mttsch mttsch commented Nov 17, 2022

The expected behavior would be that the parent constructor is only called once.

The expected behavior would be that the parent constructor is only called once.
@johanadivare
Copy link
Contributor

johanadivare commented Nov 23, 2022

That is indeed strange we ca probably handle this in the rector rule @mttsch do you want to fix it yourself?

@mttsch
Copy link
Contributor Author

mttsch commented Nov 23, 2022

@johanadivare I think that I am too unfamiliar with the code to fix this in the near future.

@johanadivare
Copy link
Contributor

@johanadivare I think that I am too unfamiliar with the code to fix this in the near future.

Fair i had a quick look but i dont see where the double constructor is added

@mttsch
Copy link
Contributor Author

mttsch commented Nov 24, 2022

@johanadivare I took a quick look when creating this issue and I think it relates to \Rector\Core\NodeManipulator\ClassDependencyManipulator::addConstructorDependencyWithCustomAssign() and \Rector\Core\NodeManipulator\Dependency\DependencyClassMethodDecorator::decorateConstructorWithParentDependencies(), though I might be mistaken.

mttsch added a commit to mttsch/rector-src that referenced this pull request Nov 26, 2022
If a promoted property is added to a class constructor and if this constructor method is already present in the class, there is no need to add a parent constructor call to this method just because a new property is added to the child's constructor. Adding the parent constructor call is only necessary when the child class currently has no constructor when the promoted property is added so that a new constructor method has to be added to the child class.

Fixes rectorphp/rector-symfony#275
@mttsch
Copy link
Contributor Author

mttsch commented Nov 26, 2022

@johanadivare I think that I have found the issue and fixed it in rectorphp/rector-src#3094.

mttsch added a commit to mttsch/rector-src that referenced this pull request Nov 26, 2022
If a promoted property is added to a class constructor and if this constructor method is already present in the class, there is no need to add a parent constructor call to this method just because a new promoted property is added to the child's constructor. Adding the parent constructor call is only necessary when the child class currently has no constructor when the promoted property is added so that a new constructor method has to be added to the child class.

Fixes rectorphp/rector-symfony#275
TomasVotruba pushed a commit to rectorphp/rector-src that referenced this pull request Nov 26, 2022
@mttsch
Copy link
Contributor Author

mttsch commented Nov 26, 2022

@TomasVotruba Should this PR be reopened because it was auto-closed by merging rectorphp/rector-src@9a93704?

@TomasVotruba
Copy link
Member

It seems this was a bug that was fixed in rectorphp/rector-src@9a93704

If it's not the case, it should be re-opened.

@mttsch
Copy link
Contributor Author

mttsch commented Nov 26, 2022

@TomasVotruba Yes, it was fixed by that commit but the test in that commit covers a different rule than this test does so it would cover the change for two different scenarios, which might not be necessary.

I was asking about the reopening because I lack the permission to do so.

@TomasVotruba TomasVotruba reopened this Nov 26, 2022
@TomasVotruba
Copy link
Member

I see :)

In that case, next time the "closes x" should link only issue, not the PR. This test fixture should've been part of the fixing PR so it's complete work in one PR.

@mttsch
Copy link
Contributor Author

mttsch commented Nov 26, 2022

This test fixture should've been part of the fixing PR so it's complete work in one PR.

The fix was in a different repository, thus different PRs.

@TomasVotruba
Copy link
Member

TomasVotruba commented Nov 26, 2022

I see, got it 👍

Thanks for explaning

@TomasVotruba TomasVotruba merged commit 2a55ef3 into rectorphp:main Nov 26, 2022
@mttsch mttsch deleted the test/GetParameterToConstructorInjectionRector branch November 26, 2022 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants