1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 00:56:08 +02:00

More cleanups

This commit is contained in:
Jordi Boggiano
2022-03-05 14:34:21 +01:00
parent 657ff7f916
commit 6b5bd6af5b
11 changed files with 114 additions and 49 deletions

View File

@@ -21,9 +21,12 @@ use Monolog\LogRecord;
*/
class UidProcessor implements ProcessorInterface, ResettableInterface
{
/** @var string */
private $uid;
/** @var non-empty-string */
private string $uid;
/**
* @param int<1, 32> $length
*/
public function __construct(int $length = 7)
{
if ($length > 32 || $length < 1) {
@@ -53,6 +56,10 @@ class UidProcessor implements ProcessorInterface, ResettableInterface
$this->uid = $this->generateUid(strlen($this->uid));
}
/**
* @param positive-int $length
* @return non-empty-string
*/
private function generateUid(int $length): string
{
return substr(bin2hex(random_bytes((int) ceil($length / 2))), 0, $length);