Skip to content

Commit

Permalink
Fix linting, psalm
Browse files Browse the repository at this point in the history
Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
  • Loading branch information
hweihwang committed Apr 2, 2024
1 parent 7eca1c1 commit 3b936ff
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 212 deletions.
11 changes: 6 additions & 5 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 12 additions & 2 deletions lib/Db/LegacyRowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<list<array{columnId: int, operator: 'begins-with'|'contains'|'ends-with'|'is-empty'|'is-equal'|'is-greater-than'|'is-greater-than-or-equal'|'is-lower-than'|'is-lower-than-or-equal', value: float|int|string}>> $filters
*/
private function getFilterGroups(IQueryBuilder $qb, array $filters): array {
$filterGroups = [];
foreach ($filters as $groupIndex => $filterGroup) {
$filterGroups[] = $qb->expr()->andX(...$this->getInnerFilterExpressions($qb, $filterGroup, $groupIndex));
Expand Down Expand Up @@ -149,7 +154,12 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI
}
}

private function addOrderByRules(IQueryBuilder $qb, $sortArray) {
/**
* @param (int|string)[][] $sortArray
*
* @psalm-param list<array{columnId: int, mode: 'ASC'|'DESC'}> $sortArray
*/
private function addOrderByRules(IQueryBuilder $qb, array $sortArray) {
foreach ($sortArray as $index => $sortRule) {
$sortMode = $sortRule['mode'];
if (!in_array($sortMode, ['ASC', 'DESC'])) {
Expand Down
5 changes: 4 additions & 1 deletion lib/Db/RowCellSuper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 11 additions & 15 deletions lib/Event/RowDeletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
public function getUserId(): string {
return $this->userId;
}
}
26 changes: 11 additions & 15 deletions lib/Event/TableDeletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
public function getUserId(): string {
return $this->userId;
}
}
33 changes: 14 additions & 19 deletions lib/Event/TableOwnershipTransferredEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
public function getToUserId(): string {
return $this->toUserId;
}
}
26 changes: 11 additions & 15 deletions lib/Event/ViewDeletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
public function getUserId(): string {
return $this->userId;
}
}
38 changes: 19 additions & 19 deletions lib/Listener/WhenRowDeletedAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event|RowDeletedEvent>
*/
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,
]);
}
}
$this->auditLogService->log("Row with ID: $rowId was deleted by user with ID: $userId", [
'row' => $row->jsonSerialize(),
'userId' => $userId,
]);
}
}
36 changes: 18 additions & 18 deletions lib/Listener/WhenTableDeletedAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event|TableDeletedEvent>
*/
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,
]);
}
}
$this->auditLogService->log("Table with ID: $table->id was deleted by user with ID: $userId", [
'table' => $table->jsonSerialize(),
'userId' => $userId,
]);
}
}
40 changes: 20 additions & 20 deletions lib/Listener/WhenTableTransferredAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event|TableOwnershipTransferredEvent>
*/
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,
]);
}
}
$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,
]);
}
}
36 changes: 18 additions & 18 deletions lib/Listener/WhenViewDeletedAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event|ViewDeletedEvent>
*/
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,
]);
}
}
$this->auditLogService->log("View with ID: $view->id was deleted by user with ID: $userId", [
'view' => $view->jsonSerialize(),
'userId' => $userId,
]);
}
}
Loading

0 comments on commit 3b936ff

Please sign in to comment.