diff --git a/lib/Doctrine/Deprecations/Deprecation.php b/lib/Doctrine/Deprecations/Deprecation.php index 971111f..a5a6d9f 100644 --- a/lib/Doctrine/Deprecations/Deprecation.php +++ b/lib/Doctrine/Deprecations/Deprecation.php @@ -56,7 +56,10 @@ class Deprecation private static $ignoredPackages = []; /** @var array */ - private static $ignoredLinksCount = []; + private static $triggeredLinkCounts = []; + + /** @var array */ + private static $ignoredLinks = []; /** @var bool */ private static $deduplication = true; @@ -78,13 +81,17 @@ public static function trigger(string $package, string $link, string $message, . return; } - if (array_key_exists($link, self::$ignoredLinksCount)) { - self::$ignoredLinksCount[$link]++; + if (isset(self::$ignoredLinks[$link])) { + return; + } + + if (array_key_exists($link, self::$triggeredLinkCounts)) { + self::$triggeredLinkCounts[$link]++; } else { - self::$ignoredLinksCount[$link] = 1; + self::$triggeredLinkCounts[$link] = 1; } - if (self::$deduplication === true && self::$ignoredLinksCount[$link] > 1) { + if (self::$deduplication === true && self::$triggeredLinkCounts[$link] > 1) { return; } @@ -141,13 +148,17 @@ public static function triggerIfCalledFromOutside(string $package, string $link, } } - if (array_key_exists($link, self::$ignoredLinksCount)) { - self::$ignoredLinksCount[$link]++; + if (isset(self::$ignoredLinks[$link])) { + return; + } + + if (array_key_exists($link, self::$triggeredLinkCounts)) { + self::$triggeredLinkCounts[$link]++; } else { - self::$ignoredLinksCount[$link] = 1; + self::$triggeredLinkCounts[$link] = 1; } - if (self::$deduplication === true && self::$ignoredLinksCount[$link] > 1) { + if (self::$deduplication === true && self::$triggeredLinkCounts[$link] > 1) { return; } @@ -235,9 +246,10 @@ public static function disable(): void self::$type = self::TYPE_NONE; self::$logger = null; self::$deduplication = true; + self::$ignoredLinks = []; - foreach (self::$ignoredLinksCount as $link => $count) { - self::$ignoredLinksCount[$link] = 0; + foreach (self::$triggeredLinkCounts as $link => $count) { + self::$triggeredLinkCounts[$link] = 0; } } @@ -249,13 +261,13 @@ public static function ignorePackage(string $packageName): void public static function ignoreDeprecations(string ...$links): void { foreach ($links as $link) { - self::$ignoredLinksCount[$link] = 0; + self::$ignoredLinks[$link] = true; } } public static function getUniqueTriggeredDeprecationsCount(): int { - return array_reduce(self::$ignoredLinksCount, static function (int $carry, int $count) { + return array_reduce(self::$triggeredLinkCounts, static function (int $carry, int $count) { return $carry + $count; }, 0); } @@ -267,7 +279,7 @@ public static function getUniqueTriggeredDeprecationsCount(): int */ public static function getTriggeredDeprecations(): array { - return self::$ignoredLinksCount; + return self::$triggeredLinkCounts; } /** diff --git a/tests/Doctrine/Deprecations/DeprecationTest.php b/tests/Doctrine/Deprecations/DeprecationTest.php index 086baa8..482a0f0 100644 --- a/tests/Doctrine/Deprecations/DeprecationTest.php +++ b/tests/Doctrine/Deprecations/DeprecationTest.php @@ -29,7 +29,7 @@ public function setUp(): void $reflectionProperty->setAccessible(true); $reflectionProperty->setValue([]); - $reflectionProperty = new ReflectionProperty(Deprecation::class, 'ignoredLinksCount'); + $reflectionProperty = new ReflectionProperty(Deprecation::class, 'triggeredLinkCounts'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue([]); @@ -202,6 +202,23 @@ public function testDeprecationWithIgnoredPackage(): void $this->assertEquals(['https://github.com/doctrine/orm/issue/1234' => 1], Deprecation::getTriggeredDeprecations()); } + public function testDeprecationWithIgnoredLink(): void + { + Deprecation::enableWithTriggerError(); + Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issue/1234'); + + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issue/1234', + 'this is deprecated %s %d', + 'foo', + 1234 + ); + + $this->assertEquals(0, Deprecation::getUniqueTriggeredDeprecationsCount()); + $this->assertEquals([], Deprecation::getTriggeredDeprecations()); + } + public function testDeprecationIfCalledFromOutside(): void { Deprecation::enableWithTriggerError();