Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(files_versions): Refactor function for lisibility #48325

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a cs fixer rule for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rector does this as well, I've never seen anyone use this syntax in recent years so it is only in legacy code anyway.

return;
}

Expand Down
Loading