From 109b84b025f75d84845a4a5a299861242d4fa43f Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 5 Mar 2021 15:02:35 +0100 Subject: [PATCH] Add return type to functions Signed-off-by: Roeland Jago Douma --- apps/admin_audit/lib/Actions/Action.php | 2 +- .../admin_audit/lib/Actions/AppManagement.php | 6 ++--- apps/admin_audit/lib/Actions/Auth.php | 6 ++--- apps/admin_audit/lib/Actions/Console.php | 2 +- apps/admin_audit/lib/Actions/Files.php | 16 +++++++------- .../lib/Actions/GroupManagement.php | 10 ++++----- apps/admin_audit/lib/Actions/Security.php | 4 ++-- apps/admin_audit/lib/Actions/Sharing.php | 12 +++++----- apps/admin_audit/lib/Actions/Trashbin.php | 4 ++-- .../lib/Actions/UserManagement.php | 12 +++++----- apps/admin_audit/lib/Actions/Versions.php | 4 ++-- apps/admin_audit/lib/AppInfo/Application.php | 22 +++++++++---------- .../admin_audit/lib/BackgroundJobs/Rotate.php | 3 +++ .../tests/Actions/SecurityTest.php | 6 ++--- 14 files changed, 56 insertions(+), 53 deletions(-) diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php index 28e3281988..42540c3047 100644 --- a/apps/admin_audit/lib/Actions/Action.php +++ b/apps/admin_audit/lib/Actions/Action.php @@ -50,7 +50,7 @@ class Action { public function log(string $text, array $params, array $elements, - bool $obfuscateParameters = false) { + bool $obfuscateParameters = false): void { foreach ($elements as $element) { if (!isset($params[$element])) { if ($obfuscateParameters) { diff --git a/apps/admin_audit/lib/Actions/AppManagement.php b/apps/admin_audit/lib/Actions/AppManagement.php index e0d447b1d6..d4340a1c7b 100644 --- a/apps/admin_audit/lib/Actions/AppManagement.php +++ b/apps/admin_audit/lib/Actions/AppManagement.php @@ -32,7 +32,7 @@ class AppManagement extends Action { /** * @param string $appName */ - public function enableApp(string $appName) { + public function enableApp(string $appName): void { $this->log('App "%s" enabled', ['app' => $appName], ['app'] @@ -43,7 +43,7 @@ class AppManagement extends Action { * @param string $appName * @param string[] $groups */ - public function enableAppForGroups(string $appName, array $groups) { + public function enableAppForGroups(string $appName, array $groups): void { $this->log('App "%1$s" enabled for groups: %2$s', ['app' => $appName, 'groups' => implode(', ', $groups)], ['app', 'groups'] @@ -53,7 +53,7 @@ class AppManagement extends Action { /** * @param string $appName */ - public function disableApp(string $appName) { + public function disableApp(string $appName): void { $this->log('App "%s" disabled', ['app' => $appName], ['app'] diff --git a/apps/admin_audit/lib/Actions/Auth.php b/apps/admin_audit/lib/Actions/Auth.php index f4350dbe86..9e0ed67474 100644 --- a/apps/admin_audit/lib/Actions/Auth.php +++ b/apps/admin_audit/lib/Actions/Auth.php @@ -33,7 +33,7 @@ namespace OCA\AdminAudit\Actions; * @package OCA\AdminAudit\Actions */ class Auth extends Action { - public function loginAttempt(array $params) { + public function loginAttempt(array $params): void { $this->log( 'Login attempt: "%s"', $params, @@ -44,7 +44,7 @@ class Auth extends Action { ); } - public function loginSuccessful(array $params) { + public function loginSuccessful(array $params): void { $this->log( 'Login successful: "%s"', $params, @@ -55,7 +55,7 @@ class Auth extends Action { ); } - public function logout(array $params) { + public function logout(array $params): void { $this->log( 'Logout occurred', [], diff --git a/apps/admin_audit/lib/Actions/Console.php b/apps/admin_audit/lib/Actions/Console.php index 5b2eb11da3..ad8b8e2d0b 100644 --- a/apps/admin_audit/lib/Actions/Console.php +++ b/apps/admin_audit/lib/Actions/Console.php @@ -32,7 +32,7 @@ class Console extends Action { /** * @param $arguments */ - public function runCommand(array $arguments) { + public function runCommand(array $arguments): void { if (!isset($arguments[1]) || $arguments[1] === '_completion') { // Don't log autocompletion return; diff --git a/apps/admin_audit/lib/Actions/Files.php b/apps/admin_audit/lib/Actions/Files.php index 9b3f9fe755..79ac57927b 100644 --- a/apps/admin_audit/lib/Actions/Files.php +++ b/apps/admin_audit/lib/Actions/Files.php @@ -38,7 +38,7 @@ class Files extends Action { * * @param array $params */ - public function read(array $params) { + public function read(array $params): void { $this->log( 'File accessed: "%s"', $params, @@ -53,7 +53,7 @@ class Files extends Action { * * @param array $params */ - public function rename(array $params) { + public function rename(array $params): void { $this->log( 'File renamed: "%s" to "%s"', $params, @@ -69,7 +69,7 @@ class Files extends Action { * * @param array $params */ - public function create(array $params) { + public function create(array $params): void { if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) { return; } @@ -88,7 +88,7 @@ class Files extends Action { * * @param array $params */ - public function copy(array $params) { + public function copy(array $params): void { $this->log( 'File copied: "%s" to "%s"', $params, @@ -104,7 +104,7 @@ class Files extends Action { * * @param array $params */ - public function write(array $params) { + public function write(array $params): void { if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) { return; } @@ -123,7 +123,7 @@ class Files extends Action { * * @param array $params */ - public function update(array $params) { + public function update(array $params): void { $this->log( 'File updated: "%s"', $params, @@ -138,7 +138,7 @@ class Files extends Action { * * @param array $params */ - public function delete(array $params) { + public function delete(array $params): void { $this->log( 'File deleted: "%s"', $params, @@ -153,7 +153,7 @@ class Files extends Action { * * @param array $params */ - public function preview(array $params) { + public function preview(array $params): void { $this->log( 'Preview accessed: "%s" (width: "%s", height: "%s" crop: "%s", mode: "%s")', $params, diff --git a/apps/admin_audit/lib/Actions/GroupManagement.php b/apps/admin_audit/lib/Actions/GroupManagement.php index daef3e5fbb..b73b8182f7 100644 --- a/apps/admin_audit/lib/Actions/GroupManagement.php +++ b/apps/admin_audit/lib/Actions/GroupManagement.php @@ -45,7 +45,7 @@ class GroupManagement extends Action { * @param IGroup $group * @param IUser $user */ - public function addUser(IGroup $group, IUser $user) { + public function addUser(IGroup $group, IUser $user): void { $this->log('User "%s" added to group "%s"', [ 'group' => $group->getGID(), @@ -63,7 +63,7 @@ class GroupManagement extends Action { * @param IGroup $group * @param IUser $user */ - public function removeUser(IGroup $group, IUser $user) { + public function removeUser(IGroup $group, IUser $user): void { $this->log('User "%s" removed from group "%s"', [ 'group' => $group->getGID(), @@ -74,13 +74,13 @@ class GroupManagement extends Action { ] ); } - + /** * log create group to group event * * @param IGroup $group */ - public function createGroup(IGroup $group) { + public function createGroup(IGroup $group): void { $this->log('Group created: "%s"', [ 'group' => $group->getGID() @@ -96,7 +96,7 @@ class GroupManagement extends Action { * * @param IGroup $group */ - public function deleteGroup(IGroup $group) { + public function deleteGroup(IGroup $group): void { $this->log('Group deleted: "%s"', [ 'group' => $group->getGID() diff --git a/apps/admin_audit/lib/Actions/Security.php b/apps/admin_audit/lib/Actions/Security.php index 9093e3a842..efb0819e7c 100644 --- a/apps/admin_audit/lib/Actions/Security.php +++ b/apps/admin_audit/lib/Actions/Security.php @@ -41,7 +41,7 @@ class Security extends Action { * @param IUser $user * @param array $params */ - public function twofactorFailed(IUser $user, array $params) { + public function twofactorFailed(IUser $user, array $params): void { $params['uid'] = $user->getUID(); $params['displayName'] = $user->getDisplayName(); @@ -62,7 +62,7 @@ class Security extends Action { * @param IUser $user * @param array $params */ - public function twofactorSuccess(IUser $user, array $params) { + public function twofactorSuccess(IUser $user, array $params): void { $params['uid'] = $user->getUID(); $params['displayName'] = $user->getDisplayName(); diff --git a/apps/admin_audit/lib/Actions/Sharing.php b/apps/admin_audit/lib/Actions/Sharing.php index dc3ede0ae6..fb070c565a 100644 --- a/apps/admin_audit/lib/Actions/Sharing.php +++ b/apps/admin_audit/lib/Actions/Sharing.php @@ -43,7 +43,7 @@ class Sharing extends Action { * * @param array $params */ - public function shared(array $params) { + 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)', @@ -168,7 +168,7 @@ class Sharing extends Action { * * @param array $params */ - public function unshare(array $params) { + 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)', @@ -284,7 +284,7 @@ class Sharing extends Action { * * @param array $params */ - public function updatePermissions(array $params) { + public function updatePermissions(array $params): void { $this->log( 'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"', $params, @@ -302,7 +302,7 @@ class Sharing extends Action { * * @param array $params */ - public function updatePassword(array $params) { + public function updatePassword(array $params): void { $this->log( 'The password of the publicly shared %s "%s" with ID "%s" has been changed', $params, @@ -319,7 +319,7 @@ class Sharing extends Action { * * @param array $params */ - public function updateExpirationDate(array $params) { + public function updateExpirationDate(array $params): void { $this->log( 'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"', $params, @@ -336,7 +336,7 @@ class Sharing extends Action { * * @param array $params */ - public function shareAccessed(array $params) { + public function shareAccessed(array $params): void { $this->log( 'The shared %s with the token "%s" by "%s" has been accessed.', $params, diff --git a/apps/admin_audit/lib/Actions/Trashbin.php b/apps/admin_audit/lib/Actions/Trashbin.php index a3e050a29f..d21eeb0ca3 100644 --- a/apps/admin_audit/lib/Actions/Trashbin.php +++ b/apps/admin_audit/lib/Actions/Trashbin.php @@ -29,13 +29,13 @@ declare(strict_types=1); namespace OCA\AdminAudit\Actions; class Trashbin extends Action { - public function delete(array $params) { + public function delete(array $params): void { $this->log('File "%s" deleted from trash bin.', ['path' => $params['path']], ['path'] ); } - public function restore(array $params) { + public function restore(array $params): void { $this->log('File "%s" restored from trash bin.', ['path' => $params['filePath']], ['path'] ); diff --git a/apps/admin_audit/lib/Actions/UserManagement.php b/apps/admin_audit/lib/Actions/UserManagement.php index 33dd49f3b5..febadffef3 100644 --- a/apps/admin_audit/lib/Actions/UserManagement.php +++ b/apps/admin_audit/lib/Actions/UserManagement.php @@ -44,7 +44,7 @@ class UserManagement extends Action { * * @param array $params */ - public function create(array $params) { + public function create(array $params): void { $this->log( 'User created: "%s"', $params, @@ -59,7 +59,7 @@ class UserManagement extends Action { * * @param string $uid */ - public function assign(string $uid) { + public function assign(string $uid): void { $this->log( 'UserID assigned: "%s"', [ 'uid' => $uid ], @@ -72,7 +72,7 @@ class UserManagement extends Action { * * @param array $params */ - public function delete(array $params) { + public function delete(array $params): void { $this->log( 'User deleted: "%s"', $params, @@ -87,7 +87,7 @@ class UserManagement extends Action { * * @param string $uid */ - public function unassign(string $uid) { + public function unassign(string $uid): void { $this->log( 'UserID unassigned: "%s"', [ 'uid' => $uid ], @@ -100,7 +100,7 @@ class UserManagement extends Action { * * @param array $params */ - public function change(array $params) { + public function change(array $params): void { switch ($params['feature']) { case 'enabled': $this->log( @@ -130,7 +130,7 @@ class UserManagement extends Action { * * @param IUser $user */ - public function setPassword(IUser $user) { + public function setPassword(IUser $user): void { if ($user->getBackendClassName() === 'Database') { $this->log( 'Password of user "%s" has been changed', diff --git a/apps/admin_audit/lib/Actions/Versions.php b/apps/admin_audit/lib/Actions/Versions.php index 8594d781d7..6b4badf81b 100644 --- a/apps/admin_audit/lib/Actions/Versions.php +++ b/apps/admin_audit/lib/Actions/Versions.php @@ -29,7 +29,7 @@ declare(strict_types=1); namespace OCA\AdminAudit\Actions; class Versions extends Action { - public function rollback(array $params) { + public function rollback(array $params): void { $this->log('Version "%s" of "%s" was restored.', [ 'version' => $params['revision'], @@ -39,7 +39,7 @@ class Versions extends Action { ); } - public function delete(array $params) { + public function delete(array $params): void { $this->log('Version "%s" was deleted.', ['path' => $params['path']], ['path'] diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 3e67085e3b..d7afb96ea8 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -109,7 +109,7 @@ class Application extends App implements IBootstrap { * Register hooks in order to log them */ private function registerHooks(LoggerInterface $logger, - IServerContainer $serverContainer) { + IServerContainer $serverContainer): void { $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class)); $this->groupHooks($logger, $serverContainer->get(IGroupManager::class)); $this->authHooks($logger); @@ -129,7 +129,7 @@ class Application extends App implements IBootstrap { } private function userManagementHooks(LoggerInterface $logger, - IUserSession $userSession) { + IUserSession $userSession): void { $userActions = new UserManagement($logger); Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); @@ -143,7 +143,7 @@ class Application extends App implements IBootstrap { } private function groupHooks(LoggerInterface $logger, - IGroupManager $groupManager) { + IGroupManager $groupManager): void { $groupActions = new GroupManagement($logger); assert($groupManager instanceof GroupManager); @@ -153,7 +153,7 @@ class Application extends App implements IBootstrap { $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); } - private function sharingHooks(LoggerInterface $logger) { + private function sharingHooks(LoggerInterface $logger): void { $shareActions = new Sharing($logger); Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); @@ -165,7 +165,7 @@ class Application extends App implements IBootstrap { Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); } - private function authHooks(LoggerInterface $logger) { + private function authHooks(LoggerInterface $logger): void { $authActions = new Auth($logger); Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); @@ -174,7 +174,7 @@ class Application extends App implements IBootstrap { } private function appHooks(LoggerInterface $logger, - EventDispatcherInterface $eventDispatcher) { + EventDispatcherInterface $eventDispatcher): void { $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { $appActions = new AppManagement($logger); $appActions->enableApp($event->getAppID()); @@ -190,7 +190,7 @@ class Application extends App implements IBootstrap { } private function consoleHooks(LoggerInterface $logger, - EventDispatcherInterface $eventDispatcher) { + EventDispatcherInterface $eventDispatcher): void { $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { $appActions = new Console($logger); $appActions->runCommand($event->getArguments()); @@ -198,7 +198,7 @@ class Application extends App implements IBootstrap { } private function fileHooks(LoggerInterface $logger, - EventDispatcherInterface $eventDispatcher) { + EventDispatcherInterface $eventDispatcher): void { $fileActions = new Files($logger); $eventDispatcher->addListener( IPreview::EVENT, @@ -259,20 +259,20 @@ class Application extends App implements IBootstrap { ); } - private function versionsHooks(LoggerInterface $logger) { + private function versionsHooks(LoggerInterface $logger): void { $versionsActions = new Versions($logger); Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); } - private function trashbinHooks(LoggerInterface $logger) { + private function trashbinHooks(LoggerInterface $logger): void { $trashActions = new Trashbin($logger); Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); } private function securityHooks(LoggerInterface $logger, - EventDispatcherInterface $eventDispatcher) { + EventDispatcherInterface $eventDispatcher): void { $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { $security = new Security($logger); $security->twofactorSuccess($event->getSubject(), $event->getArguments()); diff --git a/apps/admin_audit/lib/BackgroundJobs/Rotate.php b/apps/admin_audit/lib/BackgroundJobs/Rotate.php index 4244a7e4f9..e0edbc6f4b 100644 --- a/apps/admin_audit/lib/BackgroundJobs/Rotate.php +++ b/apps/admin_audit/lib/BackgroundJobs/Rotate.php @@ -1,4 +1,7 @@ * diff --git a/apps/admin_audit/tests/Actions/SecurityTest.php b/apps/admin_audit/tests/Actions/SecurityTest.php index 6a4766fc2e..fab598615b 100644 --- a/apps/admin_audit/tests/Actions/SecurityTest.php +++ b/apps/admin_audit/tests/Actions/SecurityTest.php @@ -28,12 +28,12 @@ declare(strict_types=1); namespace OCA\AdminAudit\Tests\Actions; use OCA\AdminAudit\Actions\Security; -use OCP\ILogger; use OCP\IUser; +use Psr\Log\LoggerInterface; use Test\TestCase; class SecurityTest extends TestCase { - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var Security */ @@ -45,7 +45,7 @@ class SecurityTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->security = new Security($this->logger); $this->user = $this->createMock(IUser::class);