-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TrapHandle: add
once()
and times()
method to limit count of dumps;
- Loading branch information
Showing
2 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Buggregator\Trap\Client\TrapHandle; | ||
|
||
final class Counter | ||
{ | ||
/** @var array<non-empty-string, int<0, max>> */ | ||
private static array $counters = []; | ||
|
||
/** | ||
* Returns true if the counter of related stack trace is less than $times. In this case, the counter is incremented. | ||
*/ | ||
public static function checkAndIncrement(string $key, int $times): bool | ||
{ | ||
self::$counters[$key] ??= 0; | ||
Check failure on line 17 in src/Client/TrapHandle/Counter.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)PropertyTypeCoercion
|
||
|
||
if (self::$counters[$key] < $times) { | ||
self::$counters[$key]++; | ||
Check failure on line 20 in src/Client/TrapHandle/Counter.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)PropertyTypeCoercion
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |