Skip to content

Commit

Permalink
Remove $version identifier for first deprecation occurrence.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Feb 7, 2021
1 parent 9d2dfb1 commit 8146928
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Enable Doctrine deprecations to be sent to a PSR3 logger:
\Doctrine\Deprecations\Deprecation::enableWithPsrLogger($logger);
```

Disable deprecations from a package, starting at given version and above
Disable deprecations from a package

```php
\Doctrine\Deprecations\Deprecation::ignorePackage("doctrine/orm", "2.8");
\Doctrine\Deprecations\Deprecation::ignorePackage("doctrine/orm");
```

Disable triggering about specific deprecations:
Expand All @@ -52,7 +52,6 @@ foreach ($deprecations as $identifier => $count) {
```php
\Doctrine\Deprecations\Deprecation::trigger(
"doctrine/orm",
"2.7",
"https://link/to/deprecations-description",
"message"
);
Expand All @@ -64,7 +63,6 @@ the message.
```php
\Doctrine\Deprecations\Deprecation::trigger(
"doctrine/orm",
"2.7",
"https://github.com/doctrine/orm/issue/1234",
"message %s %d",
"foo",
Expand Down
19 changes: 8 additions & 11 deletions lib/Doctrine/Deprecations/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Deprecation
*
* @param mixed $args
*/
public static function trigger(string $package, string $version, string $link, string $message, ...$args): void
public static function trigger(string $package, string $link, string $message, ...$args): void
{
if (array_key_exists($link, self::$ignoredLinks)) {
self::$ignoredLinks[$link]++;
Expand All @@ -83,7 +83,7 @@ public static function trigger(string $package, string $version, string $link, s
return;
}

if (isset(self::$ignoredPackages[$package]) && version_compare($version, self::$ignoredPackages[$package]) >= 0) {
if (isset(self::$ignoredPackages[$package])) {
return;
}

Expand All @@ -93,23 +93,21 @@ public static function trigger(string $package, string $version, string $link, s

if (self::$type === self::TYPE_TRIGGER_ERROR) {
$message .= sprintf(
' (%s:%s, %s, since %s %s)',
' (%s:%s, %s, package %s)',
basename($backtrace[0]['file']),
$backtrace[0]['line'],
$link,
$package,
$version
$package
);

trigger_error($message, E_USER_DEPRECATED);
} elseif (self::$type === self::TYPE_TRIGGER_SUPPRESSED_ERROR) {
$message .= sprintf(
' (%s:%s, %s, since %s %s)',
' (%s:%s, %s, pcakage %s)',
basename($backtrace[0]['file']),
$backtrace[0]['line'],
$link,
$package,
$version
$package
);

@trigger_error($message, E_USER_DEPRECATED);
Expand All @@ -120,7 +118,6 @@ public static function trigger(string $package, string $version, string $link, s
];

$context['package'] = $package;
$context['since'] = $version;
$context['link'] = $link;

self::$logger->notice($message, $context);
Expand Down Expand Up @@ -153,9 +150,9 @@ public static function disable(): void
}
}

public static function ignorePackage(string $packageName, string $version = '0.0.1'): void
public static function ignorePackage(string $packageName): void
{
self::$ignoredPackages[$packageName] = $version;
self::$ignoredPackages[$packageName] = true;
}

public static function ignoreDeprecations(string ...$links): void
Expand Down
7 changes: 1 addition & 6 deletions tests/Doctrine/Deprecations/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function testDeprecation(): void
try {
Deprecation::trigger(
'doctrine/orm',
'2.7',
'https://github.com/doctrine/deprecations/1234',
'this is deprecated %s %d',
'foo',
Expand All @@ -73,7 +72,6 @@ public function testDeprecationResetsCounts(): void
try {
Deprecation::trigger(
'doctrine/orm',
'2.7',
'https://github.com/doctrine/deprecations/1234',
'this is deprecated %s %d',
'foo',
Expand All @@ -93,7 +91,6 @@ public function testDeprecationWithPsrLogger(): void
$mock->method('notice')->with('this is deprecated foo 1234', $this->callback(function ($context) {
$this->assertEquals(__FILE__, $context['file']);
$this->assertEquals('doctrine/orm', $context['package']);
$this->assertEquals('2.7', $context['since']);
$this->assertEquals('https://github.com/doctrine/deprecations/2222', $context['link']);

return true;
Expand All @@ -103,7 +100,6 @@ public function testDeprecationWithPsrLogger(): void

Deprecation::trigger(
'doctrine/orm',
'2.7',
'https://github.com/doctrine/deprecations/2222',
'this is deprecated %s %d',
'foo',
Expand All @@ -114,11 +110,10 @@ public function testDeprecationWithPsrLogger(): void
public function testDeprecationWithIgnoredPackage(): void
{
Deprecation::enableWithTriggerError();
Deprecation::ignorePackage('doctrine/orm', '2.8');
Deprecation::ignorePackage('doctrine/orm');

Deprecation::trigger(
'doctrine/orm',
'2.8',
'https://github.com/doctrine/orm/issue/1234',
'this is deprecated %s %d',
'foo',
Expand Down

0 comments on commit 8146928

Please sign in to comment.