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

How can I get the constructor args from a New_? #6001

Closed
jdart opened this issue Mar 26, 2021 · 3 comments
Closed

How can I get the constructor args from a New_? #6001

jdart opened this issue Mar 26, 2021 · 3 comments

Comments

@jdart
Copy link

jdart commented Mar 26, 2021

I'm using \Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector which adds a parameter to the class constructor. I was thinking I'd need to write a new Rector to add the new parameter in unit tests where the class would be constructed by hand. My first attempt was to look through all Node\Expr\New_ but I can't figure out how to get and look at the signature of the constructor to see if I need to modify anything. Is that a good way to go about solving adding the parameter or is there a better way?

@TomasVotruba
Copy link
Member

Hi, we have a repository dedicated to node overview, that is exactly for these questions :)

Here, see New_ node:
https://github.com/rectorphp/php-parser-nodes-docs#phpparsernodeexprnew_

@jdart
Copy link
Author

jdart commented Mar 29, 2021

Thanks @TomasVotruba ... it just occurred to me that I could use normal php reflection to get the parameters of the constructor... does that sound like the way to go?

@TomasVotruba
Copy link
Member

👍

Reflection can be used too. We're not using native PHP reflection, but static reflections based on better-reflection package: #5665

TomasVotruba added a commit that referenced this issue Jun 22, 2024
rectorphp/rector-src@93bccca Fix message handler removal in RemoveUnusedPublicMethodParameterRector (#6001)
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

No branches or pull requests

2 participants