From 9ef272183f4166fa5511fd02120764d24c5b2344 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:31:47 +0200 Subject: [PATCH] chore(files_versions): Refactor function for lisibility Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> fix: typo --- .../lib/Listener/FileEventsListener.php | 59 +++++-------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index c078f4bc34755..2aee3bfab833a 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -64,49 +64,20 @@ public function __construct( } public function handle(Event $event): void { - if ($event instanceof NodeCreatedEvent) { - $this->created($event->getNode()); - } - - if ($event instanceof BeforeNodeTouchedEvent) { - $this->pre_touch_hook($event->getNode()); - } - - if ($event instanceof NodeTouchedEvent) { - $this->touch_hook($event->getNode()); - } - - if ($event instanceof BeforeNodeWrittenEvent) { - $this->write_hook($event->getNode()); - } - - if ($event instanceof NodeWrittenEvent) { - $this->post_write_hook($event->getNode()); - } - - if ($event instanceof BeforeNodeDeletedEvent) { - $this->pre_remove_hook($event->getNode()); - } - - if ($event instanceof NodeDeletedEvent) { - $this->remove_hook($event->getNode()); - } - - if ($event instanceof NodeRenamedEvent) { - $this->rename_hook($event->getSource(), $event->getTarget()); - } - - if ($event instanceof NodeCopiedEvent) { - $this->copy_hook($event->getSource(), $event->getTarget()); - } - - if ($event instanceof BeforeNodeRenamedEvent) { - $this->pre_renameOrCopy_hook($event->getSource(), $event->getTarget()); - } - - if ($event instanceof BeforeNodeCopiedEvent) { - $this->pre_renameOrCopy_hook($event->getSource(), $event->getTarget()); - } + match (true) { + $event instanceof NodeCreatedEvent => $this->created($event->getNode()), + $event instanceof BeforeNodeTouchedEvent => $this->pre_touch_hook($event->getNode()), + $event instanceof NodeTouchedEvent => $this->touch_hook($event->getNode()), + $event instanceof BeforeNodeWrittenEvent => $this->write_hook($event->getNode()), + $event instanceof NodeWrittenEvent => $this->post_write_hook($event->getNode()), + $event instanceof BeforeNodeDeletedEvent => $this->pre_remove_hook($event->getNode()), + $event instanceof NodeDeletedEvent => $this->remove_hook($event->getNode()), + $event instanceof NodeRenamedEvent => $this->rename_hook($event->getSource(), $event->getTarget()), + $event instanceof NodeCopiedEvent => $this->copy_hook($event->getSource(), $event->getTarget()), + $event instanceof BeforeNodeRenamedEvent => $this->pre_renameOrCopy_hook($event->getSource(), $event->getTarget()), + $event instanceof BeforeNodeCopiedEvent => $this->pre_renameOrCopy_hook($event->getSource(), $event->getTarget()), + default => null, // Fallback if no event matches + }; } public function pre_touch_hook(Node $node): void { @@ -331,7 +302,7 @@ public function pre_renameOrCopy_hook(Node $source, Node $target): void { $manager = Filesystem::getMountManager(); $mount = $manager->find($absOldPath); $internalPath = $mount->getInternalPath($absOldPath); - if ($internalPath === '' and $mount instanceof MoveableMount) { + if ($internalPath === '' && $mount instanceof MoveableMount) { return; }