phpstan-nette icon indicating copy to clipboard operation
phpstan-nette copied to clipboard

Added Nette\Caching\Cache dynamic return type extensions

Open adaamz opened this issue 4 years ago • 4 comments

adaamz avatar Apr 27 '20 11:04 adaamz

Hi, I worry that some cases will not work well, for example:


	/**
	 * @template TFallback
	 * @param mixed $key
	 * @param (callable(mixed): TFallback)|null $fallback
	 * @return TFallback
	 */
 	public function load($key, callable $fallback = null)

If the fallback is not passed, we have an unresolved TFallback.

And in some other cases I'm not sure that callable(mixed) is right, there might be none or more arguments passed.

ondrejmirtes avatar Apr 27 '20 12:04 ondrejmirtes

Can we somehow tell that if no fallback is passed it should return null?

In source is this https://github.com/nette/caching/blob/be02f7e/src/Caching/Cache.php#L104, so the parameter should be only one?

adaamz avatar Apr 27 '20 12:04 adaamz

  1. TFallback - nope, at that point you can't use generics, but need a dynamic return type extension instead.
  2. There are three callable(mixed) in the stubs, is it true for all of those? What's the diferrence between fn(&$dependencies) and fn(...[&$dependencies])?

ondrejmirtes avatar Apr 27 '20 12:04 ondrejmirtes

  1. OK, introduced dynamic return type extensions for all previously stubbed methods
  2. i have no clue, im really lost in references in php :)

adaamz avatar Apr 27 '20 13:04 adaamz