improve code style
Cette révision appartient à :
Parent
8e697940fb
révision
6338b58570
@ -23,7 +23,13 @@ use RuntimeException;
|
||||
|
||||
trait ProcessorsTrait
|
||||
{
|
||||
public function applyProcessors($logger, array $processorFlags): Logger
|
||||
/**
|
||||
* @param Logger $logger
|
||||
* @param array<int|string, string|array<string, string|int>> $processorFlags
|
||||
*
|
||||
* @return Logger
|
||||
*/
|
||||
public function applyProcessors(Logger $logger, array $processorFlags): Logger
|
||||
{
|
||||
$this->applyUidProcessor($processorFlags, $logger);
|
||||
$this->applyFilterSensitiveProcessor($processorFlags, $logger);
|
||||
@ -32,11 +38,12 @@ trait ProcessorsTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $processorFlags
|
||||
* @param $logger
|
||||
* @param array<int|string, string|array<string, string|int>> $processorFlags
|
||||
* @param Logger $logger
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function applyUidProcessor(array $processorFlags, $logger): void
|
||||
protected function applyUidProcessor(array $processorFlags, Logger $logger): void
|
||||
{
|
||||
if (in_array(self::PROCESSOR_UNIQUE_ID, $processorFlags, true) ||
|
||||
in_array(self::PROCESSOR_UNIQUE_ID, array_keys($processorFlags), true)
|
||||
@ -46,11 +53,12 @@ trait ProcessorsTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $processorFlags
|
||||
* @param $logger
|
||||
* @param array<int|string, string|array<string, string|int>> $processorFlags
|
||||
* @param Logger $logger
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function applyFilterSensitiveProcessor(array $processorFlags, $logger): void
|
||||
protected function applyFilterSensitiveProcessor(array $processorFlags, Logger $logger): void
|
||||
{
|
||||
if (in_array(self::PROCESSOR_FILTERSENSITIVE, array_keys($processorFlags), true)) {
|
||||
$options = $processorFlags[self::PROCESSOR_FILTERSENSITIVE] ?? [];
|
||||
|
@ -21,14 +21,26 @@ use Monolog\Processor\ProcessorInterface;
|
||||
|
||||
class SensitiveFilterProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(protected array $secrets, protected ?string $replacement = null)
|
||||
protected string $replacement;
|
||||
|
||||
/**
|
||||
* @param string[] $secrets
|
||||
* @param string|null $replacement
|
||||
*/
|
||||
public function __construct(protected array $secrets, ?string $replacement = null)
|
||||
{
|
||||
$this->replacement ??= '*****';
|
||||
$this->replacement = $replacement ?? '*****';
|
||||
$this->convertStringsToRegex($this->secrets);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $search
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function convertStringsToRegex(array $search = []): void
|
||||
{
|
||||
$searchStrings = [];
|
||||
array_map(
|
||||
function ($search) use (&$searchStrings) {
|
||||
if (!$this->stringIsRegexp($search)) {
|
||||
@ -61,9 +73,12 @@ class SensitiveFilterProcessor implements ProcessorInterface
|
||||
$item
|
||||
);
|
||||
} elseif (is_array($item)) {
|
||||
/** @phpstan-ignore argument.type */
|
||||
$records[$key] = $this($item);
|
||||
}
|
||||
}
|
||||
|
||||
/** @phpstan-ignore return.type */
|
||||
return $records;
|
||||
}
|
||||
}
|
@ -72,8 +72,9 @@ trait SpecialHandlersTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $specialHandlerFlags
|
||||
* @param array<int|string, string|array<string, string|int>> $specialHandlerFlags
|
||||
* @param HandlerInterface $handler
|
||||
*
|
||||
* @return HandlerInterface
|
||||
*/
|
||||
protected function applyBufferHandler(array $specialHandlerFlags, HandlerInterface $handler): HandlerInterface
|
||||
@ -94,8 +95,9 @@ trait SpecialHandlersTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $specialHandlerFlags
|
||||
* @param array<int|string, string|array<string, string|int>> $specialHandlerFlags
|
||||
* @param HandlerInterface $handler
|
||||
*
|
||||
* @return HandlerInterface
|
||||
*/
|
||||
protected function applyLogOnErrorOnlyHandler(array $specialHandlerFlags, HandlerInterface $handler): HandlerInterface
|
||||
@ -114,8 +116,9 @@ trait SpecialHandlersTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $specialHandlerFlags
|
||||
* @param array<int|string, string|array<string, string|int>> $specialHandlerFlags
|
||||
* @param HandlerInterface $handler
|
||||
*
|
||||
* @return HandlerInterface
|
||||
*/
|
||||
protected function applyMakeUniqueHandler(array $specialHandlerFlags, HandlerInterface $handler): HandlerInterface
|
||||
|
@ -122,7 +122,7 @@ class SensitiveFilterProcessorTest extends ApiTestCase
|
||||
'subkey3' => [
|
||||
'subsubkey3' => 'value+password+value+secret1',
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$expected = [
|
||||
@ -135,7 +135,7 @@ class SensitiveFilterProcessorTest extends ApiTestCase
|
||||
'subkey3' => [
|
||||
'subsubkey3' => 'value+###+value+###',
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertSame(
|
||||
|
Chargement…
x
Référencer dans un nouveau ticket
Bloquer un utilisateur