-
Notifications
You must be signed in to change notification settings - Fork 430
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
Checking variable variables for object properties. #337
Conversation
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.
Also please rebase and clean up the commit history.
8475f1e
to
5944440
Compare
f16a251
to
dcb7b6c
Compare
done |
822b477
to
bdeed5a
Compare
983197a
to
b95c7c6
Compare
-> PropertyReflectionFinder->findPropertyReflectionFromNode() is now marked as internal, and we added "findPropertyReflectionsFromNode()", which return an array of FoundPropertyReflection objects
b95c7c6
to
6d51662
Compare
Hi, I've reworked your PR: #348 I reused your tests and did the most simple implementation to make the tests pass. This case is problematic as it currently leads to false positives: $data = $this->data();
foreach($data as $property => $value) {
$self->{$property} = $value;
} Can you point out what you did in your PR to make the tests pass? I feel like it's not worth to change the property rules around this case as the analysis itself needs to be more precise - the rules themselves will start working correctly once the analysis is correct. I've did a PoC of the better foreach analysis: #349 but it needs more work... |
I'm just realizing this will need a completely different solution than what I did in #349. It will need something that gets closer to https://github.com/phpstan/phpstan/milestone/12. |
Alright, so I merged #348 without changes to TypesAssignedToPropertiesRule which would require some analyser engine changes, which I can't tackle right now (I'm busy working on PHP 8 support). Thank you. |
No problem, I am happy if we can push this forward, step by step. 👍 And yes, I also realized while playing with the code and types that there are some missing information for arrays.
What I missed here was the original information from the array or from the array-shape in the elements of the array. I only found the information in |
With this pull request, we have the possibility to check variable variables object properties in foreach loops.
For static and non-static variable variables we check if the key from the array shape is available as property, and we check if the type from the array shape (or from the current variable) is compatible with the type from the class.
⇾
PropertyReflectionFinder->findPropertyReflectionFromNode()
is nowmarked as internal. New
findPropertyReflectionsFromNode()
method is added,which return an array of FoundPropertyReflection objects and I replaced all findPropertyReflectionFromNode() calls in the codebase.
Example:
This change is