diff options
author | Joas Schilling <coding@schilljs.com> | 2018-02-10 17:45:04 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-02-28 15:06:05 +0100 |
commit | 03a25410f187457f98820944624dfa8d0b8acfa6 (patch) | |
tree | 79bedfd173b2e23cfb74e3df800cdbd36bd533c7 | |
parent | 533e8351adfd5cc443c853fbb884246e8ae36b04 (diff) | |
download | nextcloud-server-03a25410f187457f98820944624dfa8d0b8acfa6.tar.gz nextcloud-server-03a25410f187457f98820944624dfa8d0b8acfa6.zip |
Extract duplicated logic into a method
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/files/lib/Activity/Provider.php | 104 |
1 files changed, 24 insertions, 80 deletions
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index 3da1f3c1157..727dbddaeee 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(); } |