0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-03-12 15:37:27 +00:00
nextcloud_server/apps/admin_audit/lib/Actions/Action.php
Côme Chilliet 25f38883f1
fix: Work around false-positive psalm taint error calling print_r in admin_audit
Same issue as var_export, print_r is listed as sink but it’s not when
 using return:true. Anyway, using the logger context feature is better.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2025-02-17 15:24:08 +01:00

66 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Actions;
use OCA\AdminAudit\IAuditLogger;
class Action {
public function __construct(
private IAuditLogger $logger,
) {
}
/**
* Log a single action with a log level of info
*
* @param string $text
* @param array $params
* @param array $elements
* @param bool $obfuscateParameters
*/
public function log(string $text,
array $params,
array $elements,
bool $obfuscateParameters = false): void {
foreach ($elements as $element) {
if (!isset($params[$element])) {
if ($obfuscateParameters) {
$this->logger->critical(
'$params["' . $element . '"] was missing.',
['app' => 'admin_audit']
);
} else {
$this->logger->critical(
'$params["' . $element . '"] was missing. Transferred value: {params}',
['app' => 'admin_audit', 'params' => $params]
);
}
return;
}
}
$replaceArray = [];
foreach ($elements as $element) {
if ($params[$element] instanceof \DateTime) {
$params[$element] = $params[$element]->format('Y-m-d H:i:s');
}
$replaceArray[] = $params[$element];
}
$this->logger->info(
vsprintf(
$text,
$replaceArray
),
[
'app' => 'admin_audit'
]
);
}
}