-
Notifications
You must be signed in to change notification settings - Fork 20
Make deduplication configurable from env #94
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
base: 1.1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,8 @@ class Deprecation | |
| /** @var array<string,bool> */ | ||
| private static $ignoredLinks = []; | ||
|
|
||
| /** @var bool */ | ||
| private static $deduplication = true; | ||
| /** @var bool|null */ | ||
| private static $deduplication; | ||
|
|
||
| /** | ||
| * Trigger a deprecation for the given package and identfier. | ||
|
|
@@ -93,7 +93,7 @@ public static function trigger(string $package, string $link, string $message, . | |
| self::$triggeredDeprecations[$link] = 1; | ||
| } | ||
|
|
||
| if (self::$deduplication === true && self::$triggeredDeprecations[$link] > 1) { | ||
| if ((self::$deduplication ?? self::getDeduplicationFromEnv()) === true && self::$triggeredDeprecations[$link] > 1) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -160,7 +160,7 @@ public static function triggerIfCalledFromOutside(string $package, string $link, | |
| self::$triggeredDeprecations[$link] = 1; | ||
| } | ||
|
|
||
| if (self::$deduplication === true && self::$triggeredDeprecations[$link] > 1) { | ||
| if ((self::$deduplication ?? self::getDeduplicationFromEnv()) === true && self::$triggeredDeprecations[$link] > 1) { | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -250,7 +250,7 @@ public static function disable(): void | |
| { | ||
| self::$type = self::TYPE_NONE; | ||
| self::$logger = null; | ||
| self::$deduplication = true; | ||
| self::$deduplication = null; | ||
| self::$ignoredLinks = []; | ||
|
|
||
| foreach (self::$triggeredDeprecations as $link => $count) { | ||
|
|
@@ -306,4 +306,15 @@ private static function getTypeFromEnv(): int | |
|
|
||
| return self::$type; | ||
| } | ||
|
|
||
| private static function getDeduplicationFromEnv(): bool | ||
| { | ||
| $envValue = $_SERVER['DOCTRINE_DEPRECATIONS_DEDUPLICATION'] ?? $_ENV['DOCTRINE_DEPRECATIONS_DEDUPLICATION'] ?? null; | ||
|
|
||
| if ($envValue === 'false' || $envValue === '0') { | ||
| return self::$deduplication = false; | ||
| } | ||
|
|
||
| return self::$deduplication = true; | ||
|
Comment on lines
+314
to
+318
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this doing here? Flipping
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| } | ||
There was a problem hiding this comment.
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 astaticfunction for it that returnsself::$deduplication ?? ...whateverDerivedFromEnv...There was a problem hiding this comment.
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