-
Notifications
You must be signed in to change notification settings - Fork 534
Read parameter default values from php8-stubs #763
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
Conversation
I added support for a lot of cases and also test coverage for them. I am at a point where default values can contain class-constants or bitwise-or of class-constants... adding support for these cases I feel I am re-building the NodeScoperResolver now for the default-values. any hint on which direction to take is welcome. |
60b46ee
to
a8d222f
Compare
this thing is ready. the only open problem (which renders the last test-case failling) is reported as phpstan/phpstan#5985 |
just updated the phpstorm stubs which fixed phpstan/phpstan#5985 the remaining errors also fail on the master branch.. therefore I think this one is ready for feedback now. |
Hi, the title of this PR says that you read default values from JetBrains/phpstorm-stubs, but the implementation looks like you're reading only php8-stubs. Also, I'd like to see more integration-like test that for example obtains FunctionReflection from ReflectionProvider and reads the default value on that. Because that test would be executed in more PHP version and environments, we'd be able to see if it also works on PHP 7.x (which assumes that JetBrains/phpstorm-stubs are really used 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.
Because there's a lot of ShouldNotHappenException, we need a test that iterates over all symbols and makes sure that none of them throw.
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.
added a separte unit test
3bf241c
to
1fafb6a
Compare
actuall I was not sure either whether the default are now coming from
I need to figure out now, how todo that. before we dive deeper into this PR I would suggest to finalize #756 first |
4b3f9d8
to
395c820
Compare
a9535dd
to
c77ab41
Compare
I'm gonna need to solve similar problems as you're trying to do here in |
c77ab41
to
c9b589c
Compare
I think this should be good as is. in case there are wholes in the type-mapping, we will see those while finishing the named parameter PR - for which this one is a prerequisite. the test-suite shows using |
47e4971
to
7e392bf
Compare
the cause of the remaining error is that phpstan cannot resolve the type of these 2 global constants:
these constants are defined in the phpstorm stubs is there anything else required to make sure phpstan can resolve their types? atm these are resolved to |
ddd20b4
to
95d480b
Compare
Hi, I've identified I need a similar thing solved not just for parameter default values, but for other issues as well. So I need Right now the problem is that BetterReflection's CompileNodeToValue is essentially "Expr -> runtime value" which isn't great for We want "Expr -> Type" which is what I think the following steps can be taken when implementing this:
The way this should be implemented is to replicate PhpParser\ConstExprEvaluator and PHPStan\BetterReflection\NodeCompiler\CompileNodeToValue to do "Expr -> Type" and not "Expr -> runtime value", and then use it in all the places instead of currently reading the runtime value... |
Superseded by #1300 |
Added support for reading parameter default values from JetBrains/phpstorm-stubs files as requested in https://github.com/phpstan/phpstan-src/pull/750/files#r745440887
Just expanded existing singnature tests with expected-default-param-values and also added a few new cases which the existing data did not cover yet.