Make deduplication configurable from env#94
Conversation
When in the context of PHPUnit tests, using a bootstrap file is not very convenient.
|
@mpdude please review |
| if ($envValue === 'false' || $envValue === '0') { | ||
| return self::$deduplication = false; | ||
| } | ||
|
|
||
| return self::$deduplication = true; |
There was a problem hiding this comment.
What is this doing here? Flipping self::$deduplication to some value as a side effect?
There was a problem hiding this comment.
🤔 what do you mean "a side effect"? If this piece of code is reached, then it means there is either no env var defined, or it is neither false nor 0. In that case, we should fallback to the value before this PR, which was true.
| } | ||
|
|
||
| if (self::$deduplication === true && self::$triggeredDeprecations[$link] > 1) { | ||
| if ((self::$deduplication ?? self::getDeduplicationFromEnv()) === true && self::$triggeredDeprecations[$link] > 1) { |
There was a problem hiding this comment.
self::$deduplication ?? self::getDeduplicationFromEnv() is a repeating pattern. I'd make a static function for it that returns self::$deduplication ?? ...whateverDerivedFromEnv...
There was a problem hiding this comment.
self::$type ?? self::getTypeFromEnv(); is also a repeating pattern (even more repeating in fact), so although I had the same idea as you, I thought I would be consistent with the existing code
That might explain 🤣 |
Well I actually reworked Here is what Claude went with: if ($envValue === 'false' || $envValue === '0') {
self::$deduplication = false;
} else {
self::$deduplication = true;
}
return self::$deduplication; |
|
So would you want to change the state of I see, as a kind of lazy initalization and avoiding the performance overhead of re-evaluating it every time... |
|
Yes, the performance overhead, and also, from a conceptual point of vue, env variables should be considered immutable. One should assume they are never going to change during the lifetime of a program. |
When in the context of PHPUnit tests, using a bootstrap file is not very convenient.
Prompted by doctrine/collections#472
Disclaimer: I used opencode + Claude Sonnet for this.