-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[12.x] Improve AggregateServiceProvider
docblocks
#56968
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
Hello @cosmastech Since you've been making a lot of great updates in this area, would you mind also taking a quick look at the docblock for: framework/src/Illuminate/Cache/RedisStore.php Line 449 in a46b551
framework/src/Illuminate/Cache/RedisStore.php Line 460 in a46b551
I think it might be inaccurate, and your input would be really helpful. |
Thanks for reaching out @AhmedAlaa4611. Let's take a look. /**
* Determine if the given value should be stored as plain value.
*
* @param mixed $value
* @return bool
*/
protected function shouldBeStoredWithoutSerialization($value): bool
{
return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value);
}
The return type is definitely bool, as it is the result of a boolean expression. Our conditions tell us:
/**
* Serialize the value.
*
* @param mixed $value
* @return mixed
*/
protected function serialize($value)
{
return $this->shouldBeStoredWithoutSerialization($value) ? $value : serialize($value);
} This one is a little bit more interesting. From the above, we know that in order to return an unserialized numeric value here, we must have a number or numeric string for our value. Otherwise, we just return the result of I think that given we have to be loose enough to allow any input Some would make the case that adding numeric-string and string is redundant. I do not fall into that camp myself, but I see that there was recently a large MR that dropped all returns types except for Again here, you could maybe do something clever with conditional return types. (Feel like @calebdw would probably have some better insight on this, as I rarely write conditional return statements). AdditionallyI think that |
Here, a combination of generics and a conditional return type would be quite effective. Furthermore, /**
* Determine if the given value should be stored as plain value.
*
* @param mixed $value
* @return bool
* @phpstan-assert-if-true numeric-string|float $value
* @phpstan-assert-if-false NAN|INF|-INF $value
*/
protected function shouldBeStoredWithoutSerialization($value): bool
{
return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value);
} However,
|
Honestly, that seems more complicated than necessary. Both of these methods are If anything, you might update the |
@cosmastech @shaedrich @calebdw Thank you all for the explanation. |
Nothing major here, just some more specific docblocks.