-
Notifications
You must be signed in to change notification settings - Fork 662
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
Provide return type of ReflectionParameter::getType() #5333
Conversation
@dbrekelmans mind fixing CS (https://circleci.com/gh/vimeo/psalm/22383)? Tests failures are unrelated, fixed in #5335 |
src/Psalm/Internal/Provider/ReturnTypeProvider/ReflectionParameterGetType.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
First, thanks for this! I think I prefer the option you presented in the original issue, following this recent dictum. Given that <?php
/**
* @immutable
*/
class ReflectionParameter {
/**
* @psalm-assert-if-true $this->getType() ReflectionType
* @psalm-assert-if-false $this->getType() null
*/
public function hasType() : bool {
return true;
}
public function getType() : ?ReflectionType {
return null;
}
} The PR is not for nought, as I'll re-use your tests. |
@muglug I'm kinda lost However, there is no assert-if-false in the stub like in your example above: How does that works then? |
I found these snippets: https://psalm.dev/r/82732b730e<?php
$method = new ReflectionMethod(stdClass::class);
$parameters = $method->getParameters();
foreach ($parameters as $parameter) {
if ($parameter->hasType()) {
$parameter->getType()->__toString();
}
else{
$parameter->getType()->__toString();
}
}
|
I mentioned it here: #5248 (comment) |
Fixes #5258
Thanks to @orklah for giving me some hints 👍