Skip to content

Conversation

@greg0ire
Copy link
Member

@greg0ire greg0ire commented Oct 22, 2025

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.

When in the context of PHPUnit tests, using a bootstrap file is not very
convenient.
@greg0ire
Copy link
Member Author

@mpdude please review

@greg0ire greg0ire requested a review from GromNaN October 22, 2025 19:44
Comment on lines +314 to +318
if ($envValue === 'false' || $envValue === '0') {
return self::$deduplication = false;
}

return self::$deduplication = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this doing here? Flipping self::$deduplication to some value as a side effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

self::$deduplication ?? self::getDeduplicationFromEnv() is a repeating pattern. I'd make a static function for it that returns self::$deduplication ?? ...whateverDerivedFromEnv...

Copy link
Member Author

Choose a reason for hiding this comment

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

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

@mpdude
Copy link
Contributor

mpdude commented Oct 22, 2025

Disclaimer: I used opencode + Claude Sonnet for this.

That might explain 🤣

@greg0ire
Copy link
Member Author

That might explain 🤣

Well I actually reworked getDeduplicationFromEnv() myself, so if you find it a bit weird, I think it's my fault :P

Here is what Claude went with:

        if ($envValue === 'false' || $envValue === '0') {
            self::$deduplication = false;
        } else {
            self::$deduplication = true;
        }

        return self::$deduplication;

@mpdude
Copy link
Contributor

mpdude commented Oct 22, 2025

So would you want to change the state of self::$deduplication from within that getter, so that the env var is evaluated only once?

I see, as a kind of lazy initalization and avoiding the performance overhead of re-evaluating it every time...

@greg0ire
Copy link
Member Author

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.

@greg0ire greg0ire added the enhancement New feature or request label Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants