From 0911f3bde17f85ee04b3c2f18a1e63283a2163d7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 10 Feb 2018 17:45:04 +0100 Subject: [PATCH] Extract duplicated logic into a method Signed-off-by: Joas Schilling --- apps/files/lib/Activity/Provider.php | 104 +++++++-------------------- 1 file changed, 24 insertions(+), 80 deletions(-) diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index 3da1f3c115..727dbddaee 100644 --- a/apps/files/lib/Activity/Provider.php +++ b/apps/files/lib/Activity/Provider.php @@ -101,6 +101,14 @@ class Provider implements IProvider { return $this->parseLongVersion($event, $previousEvent); } + protected function setIcon(IEvent $event, $icon) { + if ($this->activityManager->getRequirePNG()) { + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', $icon . '.png'))); + } else { + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', $icon . '.svg'))); + } + } + /** * @param IEvent $event * @param IEvent|null $previousEvent @@ -113,41 +121,21 @@ class Provider implements IProvider { if ($event->getSubject() === 'created_by') { $subject = $this->l->t('Created by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); - } + $this->setIcon($event, 'add-color'); } else if ($event->getSubject() === 'changed_by') { $subject = $this->l->t('Changed by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'deleted_by') { $subject = $this->l->t('Deleted by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); - } + $this->setIcon($event, 'delete-color'); } else if ($event->getSubject() === 'restored_by') { $subject = $this->l->t('Restored by {user}'); } else if ($event->getSubject() === 'renamed_by') { $subject = $this->l->t('Renamed by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'moved_by') { $subject = $this->l->t('Moved by {user}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else { throw new \InvalidArgumentException(); } @@ -174,85 +162,41 @@ class Provider implements IProvider { if ($event->getSubject() === 'created_self') { $subject = $this->l->t('You created {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); - } + $this->setIcon($event, 'add-color'); } else if ($event->getSubject() === 'created_by') { $subject = $this->l->t('{user} created {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); - } + $this->setIcon($event, 'add-color'); } else if ($event->getSubject() === 'created_public') { $subject = $this->l->t('{file} was created in a public folder'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); - } + $this->setIcon($event, 'add-color'); } else if ($event->getSubject() === 'changed_self') { $subject = $this->l->t('You changed {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'changed_by') { $subject = $this->l->t('{user} changed {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'deleted_self') { $subject = $this->l->t('You deleted {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); - } + $this->setIcon($event, 'delete-color'); } else if ($event->getSubject() === 'deleted_by') { $subject = $this->l->t('{user} deleted {file}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); - } + $this->setIcon($event, 'delete-color'); } else if ($event->getSubject() === 'restored_self') { $subject = $this->l->t('You restored {file}'); } else if ($event->getSubject() === 'restored_by') { $subject = $this->l->t('{user} restored {file}'); } else if ($event->getSubject() === 'renamed_self') { $subject = $this->l->t('You renamed {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'renamed_by') { $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'moved_self') { $subject = $this->l->t('You moved {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else if ($event->getSubject() === 'moved_by') { $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); - if ($this->activityManager->getRequirePNG()) { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); - } else { - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); - } + $this->setIcon($event, 'change'); } else { throw new \InvalidArgumentException(); }