Skip to content

Commit

Permalink
chore(files_versions): Refactor function for lisibility
Browse files Browse the repository at this point in the history
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

fix: typo
  • Loading branch information
solracsf committed Sep 24, 2024
1 parent 3e72210 commit 9ef2721
Showing 1 changed file with 15 additions and 44 deletions.
59 changes: 15 additions & 44 deletions apps/files_versions/lib/Listener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9ef2721

Please sign in to comment.