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
Error when calling ReflectionAttribute::newInstance() #9877
Comments
This bug report is missing a link to reproduction at phpstan.org/try. It will most likely be closed after manual review. |
The bug appeared when a custom rule was used so it's impossible to reproduce on phpstan.org. |
Please link or post how the constructors of attribute classes under the |
https://github.com/zircote/swagger-php/blob/master/src/Attributes/RequestBody.php (and other files within that directory) |
You can send a bugfix to ondrejmirtes/BetterReflection if you The problem is that the "named argument" part is lost here: https://github.com/ondrejmirtes/BetterReflection/blob/851396550f122394fab96de837cf2f19db8278f7/src/NodeCompiler/CompileNodeToValue.php#L275-L291 Because the argument name isn't present as the array key, but inside |
Yeah I did find that place. I don't think |
No, the issue is that |
Nevermind you answered that above. |
Well you have You need to do a similar job that's done here: https://github.com/ondrejmirtes/BetterReflection/blob/851396550f122394fab96de837cf2f19db8278f7/src/Reflection/ReflectionAttribute.php#L49 |
I'm unable to run the tests locally. I cloned the project, checked out the commit you linked, ran
On second try they still fail but with different errors that don't make any sense either.
|
Yes, working with this fork isn't straightforward. You need to:
If the tests fail, you need to |
But honestly I'd accept this change without a new test. We can test it integration-wise in phpstan-src instead. |
Ah so it's better to make the change on top of the latest two commits, test it and then cherry pick it to a branch without those commits. Okay. :) |
You're gonna get conflicts that way because those generated commits change the source quite significantly. |
The patch is simple enough that I didn't get any conflicts that way. 😆 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
I'm unsure where exactly the error is but most likely somewhere in https://github.com/ondrejmirtes/BetterReflection rather than phpstan.
What happened is this. I switched my app from annotations to attributes. And some of them are causing a nasty issue. For instance:
We have a custom phpstan rule which is analyzing these attributes. To do that it gets the
ReflectionAttribute
instance from reflection and calls->newInstance()
. Which causes an error like this:Apparently it's trying to put the
[new OA\MediaType(mediaType: 'application/json')]
value into the$ref
argument ofRequestBody::__construct()
instead of the$content
argument. Somewhere somehow the args array passed toRequestBody
lost the named arguments information and puts the value to the first argument (ref) instead of the one I specified (content).Full stacktrace when I ran this with
--debug
:The text was updated successfully, but these errors were encountered: