Add return type to functions

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2021-03-05 15:02:35 +01:00
parent f5dc657e94
commit 109b84b025
14 changed files with 56 additions and 53 deletions

View File

@ -50,7 +50,7 @@ class Action {
public function log(string $text, public function log(string $text,
array $params, array $params,
array $elements, array $elements,
bool $obfuscateParameters = false) { bool $obfuscateParameters = false): void {
foreach ($elements as $element) { foreach ($elements as $element) {
if (!isset($params[$element])) { if (!isset($params[$element])) {
if ($obfuscateParameters) { if ($obfuscateParameters) {

View File

@ -32,7 +32,7 @@ class AppManagement extends Action {
/** /**
* @param string $appName * @param string $appName
*/ */
public function enableApp(string $appName) { public function enableApp(string $appName): void {
$this->log('App "%s" enabled', $this->log('App "%s" enabled',
['app' => $appName], ['app' => $appName],
['app'] ['app']
@ -43,7 +43,7 @@ class AppManagement extends Action {
* @param string $appName * @param string $appName
* @param string[] $groups * @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', $this->log('App "%1$s" enabled for groups: %2$s',
['app' => $appName, 'groups' => implode(', ', $groups)], ['app' => $appName, 'groups' => implode(', ', $groups)],
['app', 'groups'] ['app', 'groups']
@ -53,7 +53,7 @@ class AppManagement extends Action {
/** /**
* @param string $appName * @param string $appName
*/ */
public function disableApp(string $appName) { public function disableApp(string $appName): void {
$this->log('App "%s" disabled', $this->log('App "%s" disabled',
['app' => $appName], ['app' => $appName],
['app'] ['app']

View File

@ -33,7 +33,7 @@ namespace OCA\AdminAudit\Actions;
* @package OCA\AdminAudit\Actions * @package OCA\AdminAudit\Actions
*/ */
class Auth extends Action { class Auth extends Action {
public function loginAttempt(array $params) { public function loginAttempt(array $params): void {
$this->log( $this->log(
'Login attempt: "%s"', 'Login attempt: "%s"',
$params, $params,
@ -44,7 +44,7 @@ class Auth extends Action {
); );
} }
public function loginSuccessful(array $params) { public function loginSuccessful(array $params): void {
$this->log( $this->log(
'Login successful: "%s"', 'Login successful: "%s"',
$params, $params,
@ -55,7 +55,7 @@ class Auth extends Action {
); );
} }
public function logout(array $params) { public function logout(array $params): void {
$this->log( $this->log(
'Logout occurred', 'Logout occurred',
[], [],

View File

@ -32,7 +32,7 @@ class Console extends Action {
/** /**
* @param $arguments * @param $arguments
*/ */
public function runCommand(array $arguments) { public function runCommand(array $arguments): void {
if (!isset($arguments[1]) || $arguments[1] === '_completion') { if (!isset($arguments[1]) || $arguments[1] === '_completion') {
// Don't log autocompletion // Don't log autocompletion
return; return;

View File

@ -38,7 +38,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function read(array $params) { public function read(array $params): void {
$this->log( $this->log(
'File accessed: "%s"', 'File accessed: "%s"',
$params, $params,
@ -53,7 +53,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function rename(array $params) { public function rename(array $params): void {
$this->log( $this->log(
'File renamed: "%s" to "%s"', 'File renamed: "%s" to "%s"',
$params, $params,
@ -69,7 +69,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function create(array $params) { public function create(array $params): void {
if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) { if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) {
return; return;
} }
@ -88,7 +88,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function copy(array $params) { public function copy(array $params): void {
$this->log( $this->log(
'File copied: "%s" to "%s"', 'File copied: "%s" to "%s"',
$params, $params,
@ -104,7 +104,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function write(array $params) { public function write(array $params): void {
if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) { if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) {
return; return;
} }
@ -123,7 +123,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function update(array $params) { public function update(array $params): void {
$this->log( $this->log(
'File updated: "%s"', 'File updated: "%s"',
$params, $params,
@ -138,7 +138,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function delete(array $params) { public function delete(array $params): void {
$this->log( $this->log(
'File deleted: "%s"', 'File deleted: "%s"',
$params, $params,
@ -153,7 +153,7 @@ class Files extends Action {
* *
* @param array $params * @param array $params
*/ */
public function preview(array $params) { public function preview(array $params): void {
$this->log( $this->log(
'Preview accessed: "%s" (width: "%s", height: "%s" crop: "%s", mode: "%s")', 'Preview accessed: "%s" (width: "%s", height: "%s" crop: "%s", mode: "%s")',
$params, $params,

View File

@ -45,7 +45,7 @@ class GroupManagement extends Action {
* @param IGroup $group * @param IGroup $group
* @param IUser $user * @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"', $this->log('User "%s" added to group "%s"',
[ [
'group' => $group->getGID(), 'group' => $group->getGID(),
@ -63,7 +63,7 @@ class GroupManagement extends Action {
* @param IGroup $group * @param IGroup $group
* @param IUser $user * @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"', $this->log('User "%s" removed from group "%s"',
[ [
'group' => $group->getGID(), 'group' => $group->getGID(),
@ -74,13 +74,13 @@ class GroupManagement extends Action {
] ]
); );
} }
/** /**
* log create group to group event * log create group to group event
* *
* @param IGroup $group * @param IGroup $group
*/ */
public function createGroup(IGroup $group) { public function createGroup(IGroup $group): void {
$this->log('Group created: "%s"', $this->log('Group created: "%s"',
[ [
'group' => $group->getGID() 'group' => $group->getGID()
@ -96,7 +96,7 @@ class GroupManagement extends Action {
* *
* @param IGroup $group * @param IGroup $group
*/ */
public function deleteGroup(IGroup $group) { public function deleteGroup(IGroup $group): void {
$this->log('Group deleted: "%s"', $this->log('Group deleted: "%s"',
[ [
'group' => $group->getGID() 'group' => $group->getGID()

View File

@ -41,7 +41,7 @@ class Security extends Action {
* @param IUser $user * @param IUser $user
* @param array $params * @param array $params
*/ */
public function twofactorFailed(IUser $user, array $params) { public function twofactorFailed(IUser $user, array $params): void {
$params['uid'] = $user->getUID(); $params['uid'] = $user->getUID();
$params['displayName'] = $user->getDisplayName(); $params['displayName'] = $user->getDisplayName();
@ -62,7 +62,7 @@ class Security extends Action {
* @param IUser $user * @param IUser $user
* @param array $params * @param array $params
*/ */
public function twofactorSuccess(IUser $user, array $params) { public function twofactorSuccess(IUser $user, array $params): void {
$params['uid'] = $user->getUID(); $params['uid'] = $user->getUID();
$params['displayName'] = $user->getDisplayName(); $params['displayName'] = $user->getDisplayName();

View File

@ -43,7 +43,7 @@ class Sharing extends Action {
* *
* @param array $params * @param array $params
*/ */
public function shared(array $params) { public function shared(array $params): void {
if ($params['shareType'] === IShare::TYPE_LINK) { if ($params['shareType'] === IShare::TYPE_LINK) {
$this->log( $this->log(
'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)', '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 * @param array $params
*/ */
public function unshare(array $params) { public function unshare(array $params): void {
if ($params['shareType'] === IShare::TYPE_LINK) { if ($params['shareType'] === IShare::TYPE_LINK) {
$this->log( $this->log(
'The %s "%s" with ID "%s" has been unshared (Share ID: %s)', 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
@ -284,7 +284,7 @@ class Sharing extends Action {
* *
* @param array $params * @param array $params
*/ */
public function updatePermissions(array $params) { public function updatePermissions(array $params): void {
$this->log( $this->log(
'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"', 'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
$params, $params,
@ -302,7 +302,7 @@ class Sharing extends Action {
* *
* @param array $params * @param array $params
*/ */
public function updatePassword(array $params) { public function updatePassword(array $params): void {
$this->log( $this->log(
'The password of the publicly shared %s "%s" with ID "%s" has been changed', 'The password of the publicly shared %s "%s" with ID "%s" has been changed',
$params, $params,
@ -319,7 +319,7 @@ class Sharing extends Action {
* *
* @param array $params * @param array $params
*/ */
public function updateExpirationDate(array $params) { public function updateExpirationDate(array $params): void {
$this->log( $this->log(
'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"', 'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
$params, $params,
@ -336,7 +336,7 @@ class Sharing extends Action {
* *
* @param array $params * @param array $params
*/ */
public function shareAccessed(array $params) { public function shareAccessed(array $params): void {
$this->log( $this->log(
'The shared %s with the token "%s" by "%s" has been accessed.', 'The shared %s with the token "%s" by "%s" has been accessed.',
$params, $params,

View File

@ -29,13 +29,13 @@ declare(strict_types=1);
namespace OCA\AdminAudit\Actions; namespace OCA\AdminAudit\Actions;
class Trashbin extends Action { class Trashbin extends Action {
public function delete(array $params) { public function delete(array $params): void {
$this->log('File "%s" deleted from trash bin.', $this->log('File "%s" deleted from trash bin.',
['path' => $params['path']], ['path'] ['path' => $params['path']], ['path']
); );
} }
public function restore(array $params) { public function restore(array $params): void {
$this->log('File "%s" restored from trash bin.', $this->log('File "%s" restored from trash bin.',
['path' => $params['filePath']], ['path'] ['path' => $params['filePath']], ['path']
); );

View File

@ -44,7 +44,7 @@ class UserManagement extends Action {
* *
* @param array $params * @param array $params
*/ */
public function create(array $params) { public function create(array $params): void {
$this->log( $this->log(
'User created: "%s"', 'User created: "%s"',
$params, $params,
@ -59,7 +59,7 @@ class UserManagement extends Action {
* *
* @param string $uid * @param string $uid
*/ */
public function assign(string $uid) { public function assign(string $uid): void {
$this->log( $this->log(
'UserID assigned: "%s"', 'UserID assigned: "%s"',
[ 'uid' => $uid ], [ 'uid' => $uid ],
@ -72,7 +72,7 @@ class UserManagement extends Action {
* *
* @param array $params * @param array $params
*/ */
public function delete(array $params) { public function delete(array $params): void {
$this->log( $this->log(
'User deleted: "%s"', 'User deleted: "%s"',
$params, $params,
@ -87,7 +87,7 @@ class UserManagement extends Action {
* *
* @param string $uid * @param string $uid
*/ */
public function unassign(string $uid) { public function unassign(string $uid): void {
$this->log( $this->log(
'UserID unassigned: "%s"', 'UserID unassigned: "%s"',
[ 'uid' => $uid ], [ 'uid' => $uid ],
@ -100,7 +100,7 @@ class UserManagement extends Action {
* *
* @param array $params * @param array $params
*/ */
public function change(array $params) { public function change(array $params): void {
switch ($params['feature']) { switch ($params['feature']) {
case 'enabled': case 'enabled':
$this->log( $this->log(
@ -130,7 +130,7 @@ class UserManagement extends Action {
* *
* @param IUser $user * @param IUser $user
*/ */
public function setPassword(IUser $user) { public function setPassword(IUser $user): void {
if ($user->getBackendClassName() === 'Database') { if ($user->getBackendClassName() === 'Database') {
$this->log( $this->log(
'Password of user "%s" has been changed', 'Password of user "%s" has been changed',

View File

@ -29,7 +29,7 @@ declare(strict_types=1);
namespace OCA\AdminAudit\Actions; namespace OCA\AdminAudit\Actions;
class Versions extends Action { class Versions extends Action {
public function rollback(array $params) { public function rollback(array $params): void {
$this->log('Version "%s" of "%s" was restored.', $this->log('Version "%s" of "%s" was restored.',
[ [
'version' => $params['revision'], '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.', $this->log('Version "%s" was deleted.',
['path' => $params['path']], ['path' => $params['path']],
['path'] ['path']

View File

@ -109,7 +109,7 @@ class Application extends App implements IBootstrap {
* Register hooks in order to log them * Register hooks in order to log them
*/ */
private function registerHooks(LoggerInterface $logger, private function registerHooks(LoggerInterface $logger,
IServerContainer $serverContainer) { IServerContainer $serverContainer): void {
$this->userManagementHooks($logger, $serverContainer->get(IUserSession::class)); $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class));
$this->groupHooks($logger, $serverContainer->get(IGroupManager::class)); $this->groupHooks($logger, $serverContainer->get(IGroupManager::class));
$this->authHooks($logger); $this->authHooks($logger);
@ -129,7 +129,7 @@ class Application extends App implements IBootstrap {
} }
private function userManagementHooks(LoggerInterface $logger, private function userManagementHooks(LoggerInterface $logger,
IUserSession $userSession) { IUserSession $userSession): void {
$userActions = new UserManagement($logger); $userActions = new UserManagement($logger);
Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); Util::connectHook('OC_User', 'post_createUser', $userActions, 'create');
@ -143,7 +143,7 @@ class Application extends App implements IBootstrap {
} }
private function groupHooks(LoggerInterface $logger, private function groupHooks(LoggerInterface $logger,
IGroupManager $groupManager) { IGroupManager $groupManager): void {
$groupActions = new GroupManagement($logger); $groupActions = new GroupManagement($logger);
assert($groupManager instanceof GroupManager); assert($groupManager instanceof GroupManager);
@ -153,7 +153,7 @@ class Application extends App implements IBootstrap {
$groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']);
} }
private function sharingHooks(LoggerInterface $logger) { private function sharingHooks(LoggerInterface $logger): void {
$shareActions = new Sharing($logger); $shareActions = new Sharing($logger);
Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); 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'); Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
} }
private function authHooks(LoggerInterface $logger) { private function authHooks(LoggerInterface $logger): void {
$authActions = new Auth($logger); $authActions = new Auth($logger);
Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt');
@ -174,7 +174,7 @@ class Application extends App implements IBootstrap {
} }
private function appHooks(LoggerInterface $logger, private function appHooks(LoggerInterface $logger,
EventDispatcherInterface $eventDispatcher) { EventDispatcherInterface $eventDispatcher): void {
$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) {
$appActions = new AppManagement($logger); $appActions = new AppManagement($logger);
$appActions->enableApp($event->getAppID()); $appActions->enableApp($event->getAppID());
@ -190,7 +190,7 @@ class Application extends App implements IBootstrap {
} }
private function consoleHooks(LoggerInterface $logger, private function consoleHooks(LoggerInterface $logger,
EventDispatcherInterface $eventDispatcher) { EventDispatcherInterface $eventDispatcher): void {
$eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) {
$appActions = new Console($logger); $appActions = new Console($logger);
$appActions->runCommand($event->getArguments()); $appActions->runCommand($event->getArguments());
@ -198,7 +198,7 @@ class Application extends App implements IBootstrap {
} }
private function fileHooks(LoggerInterface $logger, private function fileHooks(LoggerInterface $logger,
EventDispatcherInterface $eventDispatcher) { EventDispatcherInterface $eventDispatcher): void {
$fileActions = new Files($logger); $fileActions = new Files($logger);
$eventDispatcher->addListener( $eventDispatcher->addListener(
IPreview::EVENT, 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); $versionsActions = new Versions($logger);
Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete');
} }
private function trashbinHooks(LoggerInterface $logger) { private function trashbinHooks(LoggerInterface $logger): void {
$trashActions = new Trashbin($logger); $trashActions = new Trashbin($logger);
Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
} }
private function securityHooks(LoggerInterface $logger, private function securityHooks(LoggerInterface $logger,
EventDispatcherInterface $eventDispatcher) { EventDispatcherInterface $eventDispatcher): void {
$eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) {
$security = new Security($logger); $security = new Security($logger);
$security->twofactorSuccess($event->getSubject(), $event->getArguments()); $security->twofactorSuccess($event->getSubject(), $event->getArguments());

View File

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de> * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
* *

View File

@ -28,12 +28,12 @@ declare(strict_types=1);
namespace OCA\AdminAudit\Tests\Actions; namespace OCA\AdminAudit\Tests\Actions;
use OCA\AdminAudit\Actions\Security; use OCA\AdminAudit\Actions\Security;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use Psr\Log\LoggerInterface;
use Test\TestCase; use Test\TestCase;
class SecurityTest extends TestCase { class SecurityTest extends TestCase {
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger; private $logger;
/** @var Security */ /** @var Security */
@ -45,7 +45,7 @@ class SecurityTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->logger = $this->createMock(ILogger::class); $this->logger = $this->createMock(LoggerInterface::class);
$this->security = new Security($this->logger); $this->security = new Security($this->logger);
$this->user = $this->createMock(IUser::class); $this->user = $this->createMock(IUser::class);