-
Notifications
You must be signed in to change notification settings - Fork 665
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 ReflectionProperty::getType() and hasType() #5584
Conversation
I found these snippets: https://psalm.dev/r/b00d652573<?php
$method = new ReflectionClass(stdClass::class);
$properties = $method->getProperties();
foreach ($properties as $property) {
if ($property->hasType()) {
$property->getType()->__toString();
}
}
|
3839970
to
21cbc21
Compare
I forgot I started this one, so tests fail and the only thing I can think of is that |
@franmomu Unfortunately |
21cbc21
to
9a0f9f9
Compare
Sure, done! Feel free to try it, the problem I think it was immutability, |
Thanks.
And this is line 6: $property->getType()->allowsNull(); Alright, now I see what you mean. Since I wonder if it would help to mark |
|
Here's an example (I think): psalm/tests/Template/ClassTemplateExtendsTest.php Lines 3442 to 3488 in 9a0f9f9
|
9a0f9f9
to
55ac52f
Compare
Thanks! done |
55ac52f
to
decb397
Compare
|
||
/** | ||
* @since 7.4 | ||
* @psalm-mutation-free |
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.
@caugner I think it works with the @psalm-mutation-free
you said 👍 (apart from adding the 7.4
check)
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.
Just to check: Did you need to add mutation-free to make the test pass? So marking the test with 7.4 was not enough?
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.
Yes, without: https://psalm.dev/r/5d10995beb
with: https://psalm.dev/r/8e9b30898d
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.
Thanks, glad to hear it works! This reminds me that I should use that annotation in my own projects as well. 🙂
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.
Thanks, looking good!
This PR tries to do as c97ee5c for
ReflectionProperty
addingReflectionProperty::hasType()
andReflectionProperty::getType()
.Right now: https://psalm.dev/r/b00d652573