From 7974ab4393a737e65b0dddc6374b0033a85e6b57 Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialrahimy@users.noreply.github.com> Date: Thu, 6 Jul 2023 11:32:49 +0330 Subject: [PATCH 1/9] Revert condition to iterate early in the loop Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/Actions/Action.php | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php index bfd67f474f943..225b89c057669 100644 --- a/apps/admin_audit/lib/Actions/Action.php +++ b/apps/admin_audit/lib/Actions/Action.php @@ -49,23 +49,26 @@ public function log(string $text, 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( - sprintf( - '$params["'.$element.'"] was missing. Transferred value: %s', - print_r($params, true) - ), - ['app' => 'admin_audit'] - ); - } - return; + if (isset($params[$element])) { + continue; } + + if ($obfuscateParameters) { + $this->logger->critical( + '$params["'.$element.'"] was missing.', + ['app' => 'admin_audit'] + ); + } else { + $this->logger->critical( + sprintf( + '$params["'.$element.'"] was missing. Transferred value: %s', + print_r($params, true) + ), + ['app' => 'admin_audit'] + ); + } + + return; } $replaceArray = []; From 202906ab0cdaf18b428aecb9bba2876b0fb1ef28 Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 6 Jul 2023 11:54:25 +0330 Subject: [PATCH 2/9] Extract codes to separate methods to more readability Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/Actions/Sharing.php | 536 +++++++++++++---------- 1 file changed, 308 insertions(+), 228 deletions(-) diff --git a/apps/admin_audit/lib/Actions/Sharing.php b/apps/admin_audit/lib/Actions/Sharing.php index 5cb3602deae7e..ff46a0600f61f 100644 --- a/apps/admin_audit/lib/Actions/Sharing.php +++ b/apps/admin_audit/lib/Actions/Sharing.php @@ -45,137 +45,177 @@ class Sharing extends Action { */ public function shared(array $params): void { if ($params['shareType'] === IShare::TYPE_LINK) { - $this->log( - 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'permissions', - 'id', - ] - ); + $this->sharedLinkType($params); } elseif ($params['shareType'] === IShare::TYPE_USER) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedUserType($params); } elseif ($params['shareType'] === IShare::TYPE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedGroupType($params); } elseif ($params['shareType'] === IShare::TYPE_ROOM) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedRoomType($params); } elseif ($params['shareType'] === IShare::TYPE_EMAIL) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedEmailType($params); } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedCircleType($params); } elseif ($params['shareType'] === IShare::TYPE_REMOTE) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedRemoteType($params); } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedRemoteGroupType($params); } elseif ($params['shareType'] === IShare::TYPE_DECK) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedDeckType($params); } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the ScienceMesh user "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); + $this->sharedSciencemeshType($params); } } + protected function sharedLinkType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'permissions', + 'id', + ] + ); + } + + protected function sharedUserType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedRoomType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedEmailType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedCircleType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedRemoteType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedRemoteGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedDeckType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedSciencemeshType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the ScienceMesh user "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + /** * Logs unsharing of data * @@ -183,127 +223,167 @@ public function shared(array $params): void { */ public function unshare(array $params): void { if ($params['shareType'] === IShare::TYPE_LINK) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'id', - ] - ); + $this->unshareLinkType($params); } elseif ($params['shareType'] === IShare::TYPE_USER) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareUserType($params); } elseif ($params['shareType'] === IShare::TYPE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareGroupType($params); } elseif ($params['shareType'] === IShare::TYPE_ROOM) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareRoomType($params); } elseif ($params['shareType'] === IShare::TYPE_EMAIL) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareEmailType($params); } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareCircleType($params); } elseif ($params['shareType'] === IShare::TYPE_REMOTE) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareRemoteType($params); } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareRemoteGroupType($params); } elseif ($params['shareType'] === IShare::TYPE_DECK) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareDeckType($params); } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the ScienceMesh user "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); + $this->unshareSciencemeshType($params); } } + protected function unshareLinkType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'id', + ] + ); + } + + protected function unshareUserType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the user "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the group "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareRoomType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the room "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareEmailType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the email recipient "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareCircleType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the circle "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareRemoteType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the remote user "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareRemoteGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the remote group "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareDeckType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the deck card "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareSciencemeshType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the ScienceMesh user "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + /** * Logs the updating of permission changes for shares * From e17c2231e9fd3873329df43d128fbece79b2489a Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:01:16 +0330 Subject: [PATCH 3/9] Replace conditions with match expression according to php8 Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/Actions/Sharing.php | 68 +++++++++--------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/apps/admin_audit/lib/Actions/Sharing.php b/apps/admin_audit/lib/Actions/Sharing.php index ff46a0600f61f..c8637e40335c7 100644 --- a/apps/admin_audit/lib/Actions/Sharing.php +++ b/apps/admin_audit/lib/Actions/Sharing.php @@ -44,27 +44,19 @@ class Sharing extends Action { * @param array $params */ public function shared(array $params): void { - if ($params['shareType'] === IShare::TYPE_LINK) { - $this->sharedLinkType($params); - } elseif ($params['shareType'] === IShare::TYPE_USER) { - $this->sharedUserType($params); - } elseif ($params['shareType'] === IShare::TYPE_GROUP) { - $this->sharedGroupType($params); - } elseif ($params['shareType'] === IShare::TYPE_ROOM) { - $this->sharedRoomType($params); - } elseif ($params['shareType'] === IShare::TYPE_EMAIL) { - $this->sharedEmailType($params); - } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) { - $this->sharedCircleType($params); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE) { - $this->sharedRemoteType($params); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) { - $this->sharedRemoteGroupType($params); - } elseif ($params['shareType'] === IShare::TYPE_DECK) { - $this->sharedDeckType($params); - } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) { - $this->sharedSciencemeshType($params); - } + match ($params['shareType']) { + IShare::TYPE_LINK => $this->sharedLinkType($params), + IShare::TYPE_USER => $this->sharedUserType($params), + IShare::TYPE_GROUP => $this->sharedGroupType($params), + IShare::TYPE_ROOM => $this->sharedRoomType($params), + IShare::TYPE_EMAIL => $this->sharedEmailType($params), + IShare::TYPE_CIRCLE => $this->sharedCircleType($params), + IShare::TYPE_REMOTE => $this->sharedRemoteType($params), + IShare::TYPE_REMOTE_GROUP => $this->sharedRemoteGroupType($params), + IShare::TYPE_DECK => $this->sharedDeckType($params), + IShare::TYPE_SCIENCEMESH => $this->sharedSciencemeshType($params), + default => null, + }; } protected function sharedLinkType(array $params): void { @@ -222,27 +214,19 @@ protected function sharedSciencemeshType(array $params): void { * @param array $params */ public function unshare(array $params): void { - if ($params['shareType'] === IShare::TYPE_LINK) { - $this->unshareLinkType($params); - } elseif ($params['shareType'] === IShare::TYPE_USER) { - $this->unshareUserType($params); - } elseif ($params['shareType'] === IShare::TYPE_GROUP) { - $this->unshareGroupType($params); - } elseif ($params['shareType'] === IShare::TYPE_ROOM) { - $this->unshareRoomType($params); - } elseif ($params['shareType'] === IShare::TYPE_EMAIL) { - $this->unshareEmailType($params); - } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) { - $this->unshareCircleType($params); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE) { - $this->unshareRemoteType($params); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) { - $this->unshareRemoteGroupType($params); - } elseif ($params['shareType'] === IShare::TYPE_DECK) { - $this->unshareDeckType($params); - } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) { - $this->unshareSciencemeshType($params); - } + match ($params['shareType']) { + IShare::TYPE_LINK => $this->unshareLinkType($params), + IShare::TYPE_USER => $this->unshareUserType($params), + IShare::TYPE_GROUP => $this->unshareGroupType($params), + IShare::TYPE_ROOM => $this->unshareRoomType($params), + IShare::TYPE_EMAIL => $this->unshareEmailType($params), + IShare::TYPE_CIRCLE => $this->unshareCircleType($params), + IShare::TYPE_REMOTE => $this->unshareRemoteType($params), + IShare::TYPE_REMOTE_GROUP => $this->unshareRemoteGroupType($params), + IShare::TYPE_DECK => $this->unshareDeckType($params), + IShare::TYPE_SCIENCEMESH => $this->unshareSciencemeshType($params), + default => null, + }; } protected function unshareLinkType(array $params): void { From 9a51a0dfc1b7b692d266f1faa012a296394442d5 Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:05:15 +0330 Subject: [PATCH 4/9] Declare methods return types Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/AuditLogger.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php index 0a7a330a7434e..1135edbbe3bbe 100644 --- a/apps/admin_audit/lib/AuditLogger.php +++ b/apps/admin_audit/lib/AuditLogger.php @@ -50,39 +50,39 @@ public function __construct(ILogFactory $logFactory, IConfig $config) { $this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); } - public function emergency($message, array $context = array()) { + public function emergency($message, array $context = array()): void { $this->parentLogger->emergency($message, $context); } - public function alert($message, array $context = array()) { + public function alert($message, array $context = array()): void { $this->parentLogger->alert($message, $context); } - public function critical($message, array $context = array()) { + public function critical($message, array $context = array()): void { $this->parentLogger->critical($message, $context); } - public function error($message, array $context = array()) { + public function error($message, array $context = array()): void { $this->parentLogger->error($message, $context); } - public function warning($message, array $context = array()) { + public function warning($message, array $context = array()): void { $this->parentLogger->warning($message, $context); } - public function notice($message, array $context = array()) { + public function notice($message, array $context = array()): void { $this->parentLogger->notice($message, $context); } - public function info($message, array $context = array()) { + public function info($message, array $context = array()): void { $this->parentLogger->info($message, $context); } - public function debug($message, array $context = array()) { + public function debug($message, array $context = array()): void { $this->parentLogger->debug($message, $context); } - public function log($level, $message, array $context = array()) { + public function log($level, $message, array $context = array()): void { $this->parentLogger->log($level, $message, $context); } } From b06913daf8f1ae27d8653fdb2a0226f429bd69f9 Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:11:10 +0330 Subject: [PATCH 5/9] Add properties type Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/AppInfo/Application.php | 3 +-- apps/admin_audit/lib/AuditLogger.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 1daf9f18ef07b..50ab773365df0 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -71,8 +71,7 @@ class Application extends App implements IBootstrap { - /** @var LoggerInterface */ - protected $logger; + protected LoggerInterface $logger; public function __construct() { parent::__construct('admin_audit'); diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php index 1135edbbe3bbe..c326573740997 100644 --- a/apps/admin_audit/lib/AuditLogger.php +++ b/apps/admin_audit/lib/AuditLogger.php @@ -32,8 +32,7 @@ */ class AuditLogger implements IAuditLogger { - /** @var LoggerInterface */ - private $parentLogger; + private LoggerInterface $parentLogger; public function __construct(ILogFactory $logFactory, IConfig $config) { $auditType = $config->getSystemValueString('log_type_audit', 'file'); From 47e4add9d32b24e2c3bf29b798a12ba180b09ced Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:41:16 +0330 Subject: [PATCH 6/9] Run php-cs-fixer Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/Actions/Action.php | 4 ++-- apps/admin_audit/lib/Actions/AppManagement.php | 1 - apps/admin_audit/lib/Actions/GroupManagement.php | 1 - apps/admin_audit/lib/Actions/UserManagement.php | 2 +- apps/admin_audit/lib/AppInfo/Application.php | 2 +- apps/admin_audit/lib/AuditLogger.php | 1 - 6 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php index 225b89c057669..5926548026b00 100644 --- a/apps/admin_audit/lib/Actions/Action.php +++ b/apps/admin_audit/lib/Actions/Action.php @@ -31,10 +31,10 @@ use OCA\AdminAudit\IAuditLogger; class Action { - public function __construct( private IAuditLogger $logger, - ) {} + ) { + } /** * Log a single action with a log level of info diff --git a/apps/admin_audit/lib/Actions/AppManagement.php b/apps/admin_audit/lib/Actions/AppManagement.php index d6bc7d2c61f26..7bd8cf4e607b8 100644 --- a/apps/admin_audit/lib/Actions/AppManagement.php +++ b/apps/admin_audit/lib/Actions/AppManagement.php @@ -27,7 +27,6 @@ namespace OCA\AdminAudit\Actions; class AppManagement extends Action { - /** * @param string $appName */ diff --git a/apps/admin_audit/lib/Actions/GroupManagement.php b/apps/admin_audit/lib/Actions/GroupManagement.php index e79b86bb88bcc..0b548b981aba5 100644 --- a/apps/admin_audit/lib/Actions/GroupManagement.php +++ b/apps/admin_audit/lib/Actions/GroupManagement.php @@ -38,7 +38,6 @@ * @package OCA\AdminAudit\Actions */ class GroupManagement extends Action { - /** * log add user to group event * diff --git a/apps/admin_audit/lib/Actions/UserManagement.php b/apps/admin_audit/lib/Actions/UserManagement.php index 02d5b60d2fa29..c66793d8a5b33 100644 --- a/apps/admin_audit/lib/Actions/UserManagement.php +++ b/apps/admin_audit/lib/Actions/UserManagement.php @@ -61,7 +61,7 @@ public function create(array $params): void { */ public function assign(string $uid): void { $this->log( - 'UserID assigned: "%s"', + 'UserID assigned: "%s"', [ 'uid' => $uid ], [ 'uid' ] ); diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 50ab773365df0..60999c8752e9c 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -60,6 +60,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; +use OCP\IServerContainer; use OCP\IUserSession; use OCP\Log\Audit\CriticalActionPerformedEvent; use OCP\Log\ILogFactory; @@ -70,7 +71,6 @@ use Psr\Log\LoggerInterface; class Application extends App implements IBootstrap { - protected LoggerInterface $logger; public function __construct() { diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php index c326573740997..52fa431e73b96 100644 --- a/apps/admin_audit/lib/AuditLogger.php +++ b/apps/admin_audit/lib/AuditLogger.php @@ -31,7 +31,6 @@ * Logger that logs in the audit log file instead of the normal log file */ class AuditLogger implements IAuditLogger { - private LoggerInterface $parentLogger; public function __construct(ILogFactory $logFactory, IConfig $config) { From 009983ed46cde781f399a5bd900419fc8c2e94b6 Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Wed, 16 Aug 2023 09:50:58 +0330 Subject: [PATCH 7/9] Remove property type to fix psalm error Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/AppInfo/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 60999c8752e9c..1563ae53c188a 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -71,7 +71,8 @@ use Psr\Log\LoggerInterface; class Application extends App implements IBootstrap { - protected LoggerInterface $logger; + /** @var LoggerInterface */ + protected $logger; public function __construct() { parent::__construct('admin_audit'); From b01dd7c23783ab2f7688ac483476c7520ccc4767 Mon Sep 17 00:00:00 2001 From: danial rahimy <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:01:54 +0330 Subject: [PATCH 8/9] Update apps/admin_audit/lib/AuditLogger.php Co-authored-by: Benjamin Gaussorgues Signed-off-by: danial rahimy <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/AuditLogger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php index 52fa431e73b96..9cea78cc34eaf 100644 --- a/apps/admin_audit/lib/AuditLogger.php +++ b/apps/admin_audit/lib/AuditLogger.php @@ -48,7 +48,7 @@ public function __construct(ILogFactory $logFactory, IConfig $config) { $this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); } - public function emergency($message, array $context = array()): void { + public function emergency($message, array $context = []): void { $this->parentLogger->emergency($message, $context); } From 5db849f95fc0aa9eb3377436688516f985783e41 Mon Sep 17 00:00:00 2001 From: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:06:55 +0330 Subject: [PATCH 9/9] Updated array usage from array() to [] for improved code readability and modern syntax. Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com> --- apps/admin_audit/lib/AuditLogger.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php index 9cea78cc34eaf..6bb434c883797 100644 --- a/apps/admin_audit/lib/AuditLogger.php +++ b/apps/admin_audit/lib/AuditLogger.php @@ -52,35 +52,35 @@ public function emergency($message, array $context = []): void { $this->parentLogger->emergency($message, $context); } - public function alert($message, array $context = array()): void { + public function alert($message, array $context = []): void { $this->parentLogger->alert($message, $context); } - public function critical($message, array $context = array()): void { + public function critical($message, array $context = []): void { $this->parentLogger->critical($message, $context); } - public function error($message, array $context = array()): void { + public function error($message, array $context = []): void { $this->parentLogger->error($message, $context); } - public function warning($message, array $context = array()): void { + public function warning($message, array $context = []): void { $this->parentLogger->warning($message, $context); } - public function notice($message, array $context = array()): void { + public function notice($message, array $context = []): void { $this->parentLogger->notice($message, $context); } - public function info($message, array $context = array()): void { + public function info($message, array $context = []): void { $this->parentLogger->info($message, $context); } - public function debug($message, array $context = array()): void { + public function debug($message, array $context = []): void { $this->parentLogger->debug($message, $context); } - public function log($level, $message, array $context = array()): void { + public function log($level, $message, array $context = []): void { $this->parentLogger->log($level, $message, $context); } }