mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-23 09:36:11 +02:00
Add Record/Level/LevelName type aliases and improve phpstan type coverage to level 6
This commit is contained in:
@@ -21,8 +21,11 @@ use Monolog\Utils;
|
||||
*/
|
||||
class MongoDBFormatter implements FormatterInterface
|
||||
{
|
||||
/** @var bool */
|
||||
private $exceptionTraceAsString;
|
||||
/** @var int */
|
||||
private $maxNestingLevel;
|
||||
/** @var bool */
|
||||
private $isLegacyMongoExt;
|
||||
|
||||
/**
|
||||
@@ -39,6 +42,8 @@ class MongoDBFormatter implements FormatterInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return scalar[]
|
||||
*/
|
||||
public function format(array $record): array
|
||||
{
|
||||
@@ -47,40 +52,48 @@ class MongoDBFormatter implements FormatterInterface
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return array<scalar[]>
|
||||
*/
|
||||
public function formatBatch(array $records): array
|
||||
{
|
||||
$formatted = [];
|
||||
foreach ($records as $key => $record) {
|
||||
$records[$key] = $this->format($record);
|
||||
$formatted[$key] = $this->format($record);
|
||||
}
|
||||
|
||||
return $records;
|
||||
return $formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string Array except when max nesting level is reached then a string "[...]"
|
||||
* @param mixed[] $array
|
||||
* @return mixed[]|string Array except when max nesting level is reached then a string "[...]"
|
||||
*/
|
||||
protected function formatArray(array $record, int $nestingLevel = 0)
|
||||
protected function formatArray(array $array, int $nestingLevel = 0)
|
||||
{
|
||||
if ($this->maxNestingLevel == 0 || $nestingLevel <= $this->maxNestingLevel) {
|
||||
foreach ($record as $name => $value) {
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
$record[$name] = $this->formatDate($value, $nestingLevel + 1);
|
||||
} elseif ($value instanceof \Throwable) {
|
||||
$record[$name] = $this->formatException($value, $nestingLevel + 1);
|
||||
} elseif (is_array($value)) {
|
||||
$record[$name] = $this->formatArray($value, $nestingLevel + 1);
|
||||
} elseif (is_object($value)) {
|
||||
$record[$name] = $this->formatObject($value, $nestingLevel + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$record = '[...]';
|
||||
if ($this->maxNestingLevel > 0 && $nestingLevel > $this->maxNestingLevel) {
|
||||
return '[...]';
|
||||
}
|
||||
|
||||
return $record;
|
||||
foreach ($array as $name => $value) {
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
$array[$name] = $this->formatDate($value, $nestingLevel + 1);
|
||||
} elseif ($value instanceof \Throwable) {
|
||||
$array[$name] = $this->formatException($value, $nestingLevel + 1);
|
||||
} elseif (is_array($value)) {
|
||||
$array[$name] = $this->formatArray($value, $nestingLevel + 1);
|
||||
} elseif (is_object($value)) {
|
||||
$array[$name] = $this->formatObject($value, $nestingLevel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return mixed[]|string
|
||||
*/
|
||||
protected function formatObject($value, int $nestingLevel)
|
||||
{
|
||||
$objectVars = get_object_vars($value);
|
||||
@@ -89,6 +102,9 @@ class MongoDBFormatter implements FormatterInterface
|
||||
return $this->formatArray($objectVars, $nestingLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]|string
|
||||
*/
|
||||
protected function formatException(\Throwable $exception, int $nestingLevel)
|
||||
{
|
||||
$formattedException = [
|
||||
|
Reference in New Issue
Block a user