Skip to content
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

Added Nette\Caching\Cache dynamic return type extensions #49

Open
wants to merge 1 commit into
base: 1.1.x
Choose a base branch
from

Conversation

adaamz
Copy link
Contributor

@adaamz adaamz commented Apr 27, 2020

No description provided.

@adaamz adaamz force-pushed the caching branch 2 times, most recently from 3434ecc to e5b5c36 Compare April 27, 2020 11:28
@ondrejmirtes
Copy link
Member

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.

@adaamz
Copy link
Contributor Author

adaamz commented Apr 27, 2020

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?

@ondrejmirtes
Copy link
Member

  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])?

@adaamz adaamz force-pushed the caching branch 2 times, most recently from 492fbf8 to 68dbcda Compare April 27, 2020 13:45
@adaamz
Copy link
Contributor Author

adaamz commented Apr 27, 2020

  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 adaamz changed the title Added Nette\Caching\Cache generic stubs Added Nette\Caching\Cache dynamic return type extensions Apr 27, 2020
}

$fallbackParameterType = $scope->getType($methodCall->args[$fallbackParameterIndex]->value);
if (!$fallbackParameterType instanceof ParametersAcceptor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better ask about ->isCallable()->yes(), get ->getCallableParametersAcceptors() and pass it to ParametersAcceptorSelector::selectFromArgs().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this? I hope i got it correctly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants