diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4515e1761..268f8e777 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -29,6 +29,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\IAppContainer; use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; use OCP\User\Events\BeforeUserDeletedEvent; @@ -57,17 +58,17 @@ public function register(IRegistrationContext $context): void { throw new Exception('Cannot include autoload. Did you run install dependencies using composer?'); } - $context->registerService(AuditLogServiceInterface::class, fn($c) => $c->query(DefaultAuditLogService::class)); + $context->registerService(AuditLogServiceInterface::class, fn (IAppContainer $c) => $c->query(DefaultAuditLogService::class)); $context->registerEventListener(BeforeUserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(DatasourceEvent::class, AnalyticsDatasourceListener::class); $context->registerEventListener(RenderReferenceEvent::class, TablesReferenceListener::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); - $context->registerEventListener(TableDeletedEvent::class, WhenTableDeletedAuditLogListener::class); - $context->registerEventListener(ViewDeletedEvent::class, WhenViewDeletedAuditLogListener::class); - $context->registerEventListener(RowDeletedEvent::class, WhenRowDeletedAuditLogListener::class); - $context->registerEventListener(TableOwnershipTransferredEvent::class, WhenTableTransferredAuditLogListener::class); + $context->registerEventListener(TableDeletedEvent::class, WhenTableDeletedAuditLogListener::class); + $context->registerEventListener(ViewDeletedEvent::class, WhenViewDeletedAuditLogListener::class); + $context->registerEventListener(RowDeletedEvent::class, WhenRowDeletedAuditLogListener::class); + $context->registerEventListener(TableOwnershipTransferredEvent::class, WhenTableTransferredAuditLogListener::class); $context->registerSearchProvider(SearchTablesProvider::class); diff --git a/lib/Db/LegacyRowMapper.php b/lib/Db/LegacyRowMapper.php index c3a4a5db2..e7a164b7f 100644 --- a/lib/Db/LegacyRowMapper.php +++ b/lib/Db/LegacyRowMapper.php @@ -116,7 +116,12 @@ private function getInnerFilterExpressions($qb, $filterGroup, int $groupIndex): return $innerFilterExpressions; } - private function getFilterGroups($qb, $filters): array { + /** + * @param (float|int|string)[][][] $filters + * + * @psalm-param non-empty-list> $filters + */ + private function getFilterGroups(IQueryBuilder $qb, array $filters): array { $filterGroups = []; foreach ($filters as $groupIndex => $filterGroup) { $filterGroups[] = $qb->expr()->andX(...$this->getInnerFilterExpressions($qb, $filterGroup, $groupIndex)); @@ -149,7 +154,12 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI } } - private function addOrderByRules(IQueryBuilder $qb, $sortArray) { + /** + * @param (int|string)[][] $sortArray + * + * @psalm-param list $sortArray + */ + private function addOrderByRules(IQueryBuilder $qb, array $sortArray) { foreach ($sortArray as $index => $sortRule) { $sortMode = $sortRule['mode']; if (!in_array($sortMode, ['ASC', 'DESC'])) { diff --git a/lib/Db/RowCellSuper.php b/lib/Db/RowCellSuper.php index 87a232b3e..e2d5962ec 100644 --- a/lib/Db/RowCellSuper.php +++ b/lib/Db/RowCellSuper.php @@ -36,7 +36,10 @@ public function __construct() { $this->addType('rowId', 'integer'); } - public function jsonSerializePreparation($value): array { + /** + * @param float|null|string $value + */ + public function jsonSerializePreparation(string|float|null $value): array { return [ 'id' => $this->id, 'columnId' => $this->columnId, diff --git a/lib/Event/RowDeletedEvent.php b/lib/Event/RowDeletedEvent.php index a3a894b51..e0566ef31 100644 --- a/lib/Event/RowDeletedEvent.php +++ b/lib/Event/RowDeletedEvent.php @@ -7,20 +7,16 @@ use OCA\Tables\Db\Row2; use OCP\EventDispatcher\Event; -final class RowDeletedEvent extends Event -{ - public function __construct(protected Row2 $row, protected string $userId) - { - parent::__construct(); - } +final class RowDeletedEvent extends Event { + public function __construct(protected Row2 $row, protected string $userId) { + parent::__construct(); + } - public function getRow(): Row2 - { - return $this->row; - } + public function getRow(): Row2 { + return $this->row; + } - public function getUserId(): string - { - return $this->userId; - } -} \ No newline at end of file + public function getUserId(): string { + return $this->userId; + } +} diff --git a/lib/Event/TableDeletedEvent.php b/lib/Event/TableDeletedEvent.php index 4acac95df..7b30915cb 100644 --- a/lib/Event/TableDeletedEvent.php +++ b/lib/Event/TableDeletedEvent.php @@ -7,20 +7,16 @@ use OCA\Tables\Db\Table; use OCP\EventDispatcher\Event; -final class TableDeletedEvent extends Event -{ - public function __construct(protected Table $table, protected string $userId) - { - parent::__construct(); - } +final class TableDeletedEvent extends Event { + public function __construct(protected Table $table, protected string $userId) { + parent::__construct(); + } - public function getTable(): Table - { - return $this->table; - } + public function getTable(): Table { + return $this->table; + } - public function getUserId(): string - { - return $this->userId; - } -} \ No newline at end of file + public function getUserId(): string { + return $this->userId; + } +} diff --git a/lib/Event/TableOwnershipTransferredEvent.php b/lib/Event/TableOwnershipTransferredEvent.php index 96bd44c69..182b65541 100644 --- a/lib/Event/TableOwnershipTransferredEvent.php +++ b/lib/Event/TableOwnershipTransferredEvent.php @@ -7,25 +7,20 @@ use OCA\Tables\Db\Table; use OCP\EventDispatcher\Event; -final class TableOwnershipTransferredEvent extends Event -{ - public function __construct(protected Table $table, protected string $toUserId, protected ?string $fromUserId = null) - { - parent::__construct(); - } +final class TableOwnershipTransferredEvent extends Event { + public function __construct(protected Table $table, protected string $toUserId, protected ?string $fromUserId = null) { + parent::__construct(); + } - public function getTable(): Table - { - return $this->table; - } + public function getTable(): Table { + return $this->table; + } - public function getFromUserId(): string - { - return $this->fromUserId; - } + public function getFromUserId(): string|null { + return $this->fromUserId; + } - public function getToUserId(): string - { - return $this->toUserId; - } -} \ No newline at end of file + public function getToUserId(): string { + return $this->toUserId; + } +} diff --git a/lib/Event/ViewDeletedEvent.php b/lib/Event/ViewDeletedEvent.php index b49512053..bcc461024 100644 --- a/lib/Event/ViewDeletedEvent.php +++ b/lib/Event/ViewDeletedEvent.php @@ -7,20 +7,16 @@ use OCA\Tables\Db\View; use OCP\EventDispatcher\Event; -final class ViewDeletedEvent extends Event -{ - public function __construct(protected View $view, protected string $userId) - { - parent::__construct(); - } +final class ViewDeletedEvent extends Event { + public function __construct(protected View $view, protected string $userId) { + parent::__construct(); + } - public function getView(): View - { - return $this->view; - } + public function getView(): View { + return $this->view; + } - public function getUserId(): string - { - return $this->userId; - } -} \ No newline at end of file + public function getUserId(): string { + return $this->userId; + } +} diff --git a/lib/Listener/WhenRowDeletedAuditLogListener.php b/lib/Listener/WhenRowDeletedAuditLogListener.php index 2fba386fb..a176ed927 100644 --- a/lib/Listener/WhenRowDeletedAuditLogListener.php +++ b/lib/Listener/WhenRowDeletedAuditLogListener.php @@ -9,25 +9,25 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -final class WhenRowDeletedAuditLogListener implements IEventListener -{ - public function __construct(protected AuditLogServiceInterface $auditLogService) - { - } +/** + * @template-implements IEventListener + */ +final class WhenRowDeletedAuditLogListener implements IEventListener { + public function __construct(protected AuditLogServiceInterface $auditLogService) { + } - public function handle(Event $event): void - { - if (!($event instanceof RowDeletedEvent)) { - return; - } + public function handle(Event $event): void { + if (!($event instanceof RowDeletedEvent)) { + return; + } - $row = $event->getRow(); - $userId = $event->getUserId(); - $rowId = $row->getId(); + $row = $event->getRow(); + $userId = $event->getUserId(); + $rowId = $row->getId(); - $this->auditLogService->log("Row with ID: $rowId was deleted by user with ID: $userId", [ - 'row' => $row->jsonSerialize(), - 'userId' => $userId, - ]); - } -} \ No newline at end of file + $this->auditLogService->log("Row with ID: $rowId was deleted by user with ID: $userId", [ + 'row' => $row->jsonSerialize(), + 'userId' => $userId, + ]); + } +} diff --git a/lib/Listener/WhenTableDeletedAuditLogListener.php b/lib/Listener/WhenTableDeletedAuditLogListener.php index 5994eaa17..c85b85230 100644 --- a/lib/Listener/WhenTableDeletedAuditLogListener.php +++ b/lib/Listener/WhenTableDeletedAuditLogListener.php @@ -9,24 +9,24 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -final class WhenTableDeletedAuditLogListener implements IEventListener -{ - public function __construct(protected AuditLogServiceInterface $auditLogService) - { - } +/** + * @template-implements IEventListener + */ +final class WhenTableDeletedAuditLogListener implements IEventListener { + public function __construct(protected AuditLogServiceInterface $auditLogService) { + } - public function handle(Event $event): void - { - if (!($event instanceof TableDeletedEvent)) { - return; - } + public function handle(Event $event): void { + if (!($event instanceof TableDeletedEvent)) { + return; + } - $table = $event->getTable(); - $userId = $event->getUserId(); + $table = $event->getTable(); + $userId = $event->getUserId(); - $this->auditLogService->log("Table with ID: $table->id was deleted by user with ID: $userId", [ - 'table' => $table->jsonSerialize(), - 'userId' => $userId, - ]); - } -} \ No newline at end of file + $this->auditLogService->log("Table with ID: $table->id was deleted by user with ID: $userId", [ + 'table' => $table->jsonSerialize(), + 'userId' => $userId, + ]); + } +} diff --git a/lib/Listener/WhenTableTransferredAuditLogListener.php b/lib/Listener/WhenTableTransferredAuditLogListener.php index fb23553a3..b4b90ff98 100644 --- a/lib/Listener/WhenTableTransferredAuditLogListener.php +++ b/lib/Listener/WhenTableTransferredAuditLogListener.php @@ -9,26 +9,26 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -final class WhenTableTransferredAuditLogListener implements IEventListener -{ - public function __construct(protected AuditLogServiceInterface $auditLogService) - { - } +/** + * @template-implements IEventListener + */ +final class WhenTableTransferredAuditLogListener implements IEventListener { + public function __construct(protected AuditLogServiceInterface $auditLogService) { + } - public function handle(Event $event): void - { - if (!($event instanceof TableOwnershipTransferredEvent)) { - return; - } + public function handle(Event $event): void { + if (!($event instanceof TableOwnershipTransferredEvent)) { + return; + } - $table = $event->getTable(); - $fromUserId = $event->getFromUserId(); - $toUserId = $event->getToUserId(); + $table = $event->getTable(); + $fromUserId = $event->getFromUserId(); + $toUserId = $event->getToUserId(); - $this->auditLogService->log("Table with ID: $table->id was transferred from user with ID: $fromUserId to user with ID: $toUserId", [ - 'table' => $table->jsonSerialize(), - 'fromUserId' => $fromUserId, - 'toUserId' => $toUserId, - ]); - } -} \ No newline at end of file + $this->auditLogService->log("Table with ID: $table->id was transferred from user with ID: $fromUserId to user with ID: $toUserId", [ + 'table' => $table->jsonSerialize(), + 'fromUserId' => $fromUserId, + 'toUserId' => $toUserId, + ]); + } +} diff --git a/lib/Listener/WhenViewDeletedAuditLogListener.php b/lib/Listener/WhenViewDeletedAuditLogListener.php index 8aad0df7b..f89a69244 100644 --- a/lib/Listener/WhenViewDeletedAuditLogListener.php +++ b/lib/Listener/WhenViewDeletedAuditLogListener.php @@ -9,24 +9,24 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -final class WhenViewDeletedAuditLogListener implements IEventListener -{ - public function __construct(protected AuditLogServiceInterface $auditLogService) - { - } +/** + * @template-implements IEventListener + */ +final class WhenViewDeletedAuditLogListener implements IEventListener { + public function __construct(protected AuditLogServiceInterface $auditLogService) { + } - public function handle(Event $event): void - { - if (!($event instanceof ViewDeletedEvent)) { - return; - } + public function handle(Event $event): void { + if (!($event instanceof ViewDeletedEvent)) { + return; + } - $view = $event->getView(); - $userId = $event->getUserId(); + $view = $event->getView(); + $userId = $event->getUserId(); - $this->auditLogService->log("View with ID: $view->id was deleted by user with ID: $userId", [ - 'view' => $view->jsonSerialize(), - 'userId' => $userId, - ]); - } -} \ No newline at end of file + $this->auditLogService->log("View with ID: $view->id was deleted by user with ID: $userId", [ + 'view' => $view->jsonSerialize(), + 'userId' => $userId, + ]); + } +} diff --git a/lib/Service/RowService.php b/lib/Service/RowService.php index b399bc93f..a88a7f2ca 100644 --- a/lib/Service/RowService.php +++ b/lib/Service/RowService.php @@ -35,25 +35,24 @@ class RowService extends SuperService { private Row2Mapper $row2Mapper; private array $tmpRows = []; // holds already loaded rows as a small cache - protected IEventDispatcher $eventDispatcher; + protected IEventDispatcher $eventDispatcher; public function __construct( - PermissionsService $permissionsService, - LoggerInterface $logger, - ?string $userId, + PermissionsService $permissionsService, + LoggerInterface $logger, + ?string $userId, ColumnMapper $columnMapper, - ViewMapper $viewMapper, - TableMapper $tableMapper, - Row2Mapper $row2Mapper, - IEventDispatcher $eventDispatcher - ) - { + ViewMapper $viewMapper, + TableMapper $tableMapper, + Row2Mapper $row2Mapper, + IEventDispatcher $eventDispatcher + ) { parent::__construct($logger, $userId, $permissionsService); $this->columnMapper = $columnMapper; $this->viewMapper = $viewMapper; $this->tableMapper = $tableMapper; $this->row2Mapper = $row2Mapper; - $this->eventDispatcher = $eventDispatcher; + $this->eventDispatcher = $eventDispatcher; } /** @@ -464,14 +463,14 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 { } try { - $deletedRow = $this->row2Mapper->delete($item); + $deletedRow = $this->row2Mapper->delete($item); - $event = new RowDeletedEvent( - row: $item, - userId: $userId - ); + $event = new RowDeletedEvent( + row: $item, + userId: $userId + ); - $this->eventDispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); return $this->filterRowResult($view ?? null, $deletedRow); } catch (Exception $e) { diff --git a/lib/Service/Support/AuditLogServiceInterface.php b/lib/Service/Support/AuditLogServiceInterface.php index ec761f1de..93eeaa962 100644 --- a/lib/Service/Support/AuditLogServiceInterface.php +++ b/lib/Service/Support/AuditLogServiceInterface.php @@ -4,7 +4,6 @@ namespace OCA\Tables\Service\Support; -interface AuditLogServiceInterface -{ - public function log(string $message, array $context): void; -} \ No newline at end of file +interface AuditLogServiceInterface { + public function log(string $message, array $context): void; +} diff --git a/lib/Service/Support/DefaultAuditLogService.php b/lib/Service/Support/DefaultAuditLogService.php index 686cbef74..e4a523719 100644 --- a/lib/Service/Support/DefaultAuditLogService.php +++ b/lib/Service/Support/DefaultAuditLogService.php @@ -7,16 +7,13 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Log\Audit\CriticalActionPerformedEvent; -final class DefaultAuditLogService implements AuditLogServiceInterface -{ - public function __construct(private IEventDispatcher $eventDispatcher) - { - } +final class DefaultAuditLogService implements AuditLogServiceInterface { + public function __construct(private IEventDispatcher $eventDispatcher) { + } - public function log(string $message, array $context): void - { - $auditEvent = new CriticalActionPerformedEvent($message, $context); + public function log(string $message, array $context): void { + $auditEvent = new CriticalActionPerformedEvent($message, $context); - $this->eventDispatcher->dispatchTyped($auditEvent); - } -} \ No newline at end of file + $this->eventDispatcher->dispatchTyped($auditEvent); + } +} diff --git a/lib/Service/TableService.php b/lib/Service/TableService.php index c6b3725e5..796390df0 100644 --- a/lib/Service/TableService.php +++ b/lib/Service/TableService.php @@ -45,7 +45,7 @@ class TableService extends SuperService { protected IL10N $l; - protected IEventDispatcher $eventDispatcher; + protected IEventDispatcher $eventDispatcher; public function __construct( PermissionsService $permissionsService, @@ -60,7 +60,7 @@ public function __construct( UserHelper $userHelper, FavoritesService $favoritesService, IL10N $l, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher ) { parent::__construct($logger, $userId, $permissionsService); $this->mapper = $mapper; @@ -72,7 +72,7 @@ public function __construct( $this->userHelper = $userHelper; $this->favoritesService = $favoritesService; $this->l = $l; - $this->eventDispatcher = $eventDispatcher; + $this->eventDispatcher = $eventDispatcher; } /** @@ -348,13 +348,13 @@ public function setOwner(int $id, string $newOwnerUserId, ?string $userId = null throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); } - $event = new TableOwnershipTransferredEvent( - table: $table, - toUserId: $newOwnerUserId, - fromUserId: $userId - ); + $event = new TableOwnershipTransferredEvent( + table: $table, + toUserId: $newOwnerUserId, + fromUserId: $userId + ); - $this->eventDispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); return $table; } @@ -431,16 +431,16 @@ public function delete(int $id, ?string $userId = null): Table { throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); } - /* - * Decouple the side logic from the core business logic - * (logging, mail sending, etc.), called handling side effects and most of them can be done asynchronously via queue. - */ - $event = new TableDeletedEvent( - table: $item, - userId: $userId - ); + /* + * Decouple the side logic from the core business logic + * (logging, mail sending, etc.), called handling side effects and most of them can be done asynchronously via queue. + */ + $event = new TableDeletedEvent( + table: $item, + userId: $userId + ); - $this->eventDispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); return $item; } diff --git a/lib/Service/ViewService.php b/lib/Service/ViewService.php index ce7cb4e85..ac8845881 100644 --- a/lib/Service/ViewService.php +++ b/lib/Service/ViewService.php @@ -41,7 +41,7 @@ class ViewService extends SuperService { protected IL10N $l; - protected IEventDispatcher $eventDispatcher; + protected IEventDispatcher $eventDispatcher; public function __construct( PermissionsService $permissionsService, @@ -53,7 +53,7 @@ public function __construct( UserHelper $userHelper, FavoritesService $favoritesService, IL10N $l, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher ) { parent::__construct($logger, $userId, $permissionsService); $this->l = $l; @@ -62,7 +62,7 @@ public function __construct( $this->rowService = $rowService; $this->userHelper = $userHelper; $this->favoritesService = $favoritesService; - $this->eventDispatcher = $eventDispatcher; + $this->eventDispatcher = $eventDispatcher; } @@ -282,14 +282,14 @@ public function delete(int $id, ?string $userId = null): View { try { $deletedView = $this->mapper->delete($view); - $event = new ViewDeletedEvent( - view: $view, - userId: $userId - ); + $event = new ViewDeletedEvent( + view: $view, + userId: $userId + ); - $this->eventDispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); - return $deletedView; + return $deletedView; } catch (\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage()); @@ -317,14 +317,14 @@ public function deleteByObject(View $view, ?string $userId = null): View { $this->mapper->delete($view); - $event = new ViewDeletedEvent( - view: $view, - userId: $userId - ); + $event = new ViewDeletedEvent( + view: $view, + userId: $userId + ); - $this->eventDispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); - return $view; + return $view; } catch (Exception $e) { $this->logger->error($e->getMessage()); throw new InternalError($e->getMessage());