[DependencyInjection] Add shuffle env processor#46883
Merged
Merged
Conversation
ro0NL
reviewed
Jul 8, 2022
Contributor
ro0NL
left a comment
There was a problem hiding this comment.
IIUC you could seed shuffle using mt_srand in tests
4c15709 to
d18d383
Compare
Member
nicolas-grekas
left a comment
There was a problem hiding this comment.
works for me, here are some comments
2caa9e5 to
a921ed4
Compare
Contributor
|
Can/will this be chainable with the « env(csv:FOO) » env processor? |
Contributor
Author
|
of course |
fabpot
reviewed
Jul 10, 2022
fabpot
requested changes
Jul 10, 2022
fabpot
approved these changes
Jul 10, 2022
Member
|
Thank you @ostrolucky. |
| } | ||
|
|
||
| if ('shuffle' === $prefix) { | ||
| \is_array($env) ? shuffle($env) : throw new RuntimeException(sprintf('Env var "%s" cannot be shuffled, expected array, got "%s".', $name, get_debug_type($env))); |
Contributor
There was a problem hiding this comment.
IMHO this is "abusing" ternary, the more "classical"
if (!\is_array($env)) {
throw new RuntimeException(sprintf('Env var "%s" cannot be shuffled, expected array, got "%s".', $name, get_debug_type($env)));
}
shuffle($env);would be better
Contributor
There was a problem hiding this comment.
Indeed, hence "IMHO" 😉 but I can try "more objective" arguments:
- it's not using the expression result (BTW: shuffle() always returns true [historically could also return false], and if designed today would probably be
: void; andthrowwasn't usable as/in an expression before PHP 8.0) - it's inconsistent with all the rest of the file (even the general codebase)
Dunno if the CS tool could flag it?
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation of this: We are specifying list of hosts for Redis cluster as env var. The way redis library unfortunately works is that it always takes first host and tries to connect to it (and after initial connection is done successfully, only then jump to other nodes). This makes first host under load much more than others. This env var processor could be used to solve it and distribute the load better.