-
Notifications
You must be signed in to change notification settings - Fork 95
Added CacheInterface stub #236
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
The However, in this case the callback actually optionally accepts Also, the parameter is annotated as Finally, please add some tests. |
/** | ||
* @template T | ||
* | ||
* @param \Symfony\Contracts\Cache\CallbackInterface<T>|callable(\Psr\Cache\CacheItemInterface): T $callback |
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.
\Psr\Cache\CacheItemInterface=
, notice the =
at the end. See https://phpstan.org/writing-php-code/phpdoc-types#callables.
For the Parameter $callback of method Symfony\Contracts\Cache\CacheInterface::get() has invalid type Psr\Cache\CacheItemInterface.
error, we need to actually add the Psr\Cache\CacheItemInterface
stub as well. It should be sufficient for it to be an empty class. We only need to know the class, we don't care about methods. See https://phpstan.org/user-guide/stub-files, Why is PHPStan complaining about “Class not found” in a stub file?
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 for the feedback, I was not familiar with the = optional
notation, actually thought it was a typo.
Can you please write some tests in https://github.com/phpstan/phpstan-symfony/blob/master/tests/Type/Symfony/ExtensionTest.php to verify this signature works as expected? More info here: https://phpstan.org/developing-extensions/testing#type-inference |
return $bar; | ||
}; | ||
|
||
assertType('Bar', $cacheInterface->get('cacheTest', $callbackCallable)); |
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.
The case with \Symfony\Contracts\Cache\CallbackInterface<T>
should also be tested.
Thank you. |
Closes #235