| Conditions | 12 |
| Paths | 12 |
| Total Lines | 58 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 44 | public function parse($language, IEvent $event, IEvent $previousEvent = null) |
||
| 45 | { |
||
| 46 | if ($event->getApp() !== 'analytics') { |
||
| 47 | throw new InvalidArgumentException(); |
||
| 48 | } |
||
| 49 | |||
| 50 | $parsedSubject = ''; |
||
| 51 | $ownActivity = ($event->getAuthor() === $this->userId); |
||
| 52 | |||
| 53 | switch ($event->getSubject()) { |
||
| 54 | case ActivityManager::SUBJECT_DATASET_ADD: |
||
| 55 | $parsedSubject = $this->l10n->t('You created a new report'); |
||
| 56 | break; |
||
| 57 | case ActivityManager::SUBJECT_DATASET_DELETE: |
||
| 58 | $parsedSubject = $this->l10n->t('You deleted report {report}'); |
||
| 59 | break; |
||
| 60 | case ActivityManager::SUBJECT_DATASET_SHARE: |
||
| 61 | if ($ownActivity) { |
||
| 62 | $parsedSubject = $this->l10n->t('You shared report {report}'); |
||
| 63 | } else { |
||
| 64 | $parsedSubject = $event->getSubjectParameters()['author'] . $this->l10n->t(' shared report {report} with you'); |
||
| 65 | } |
||
| 66 | break; |
||
| 67 | case ActivityManager::SUBJECT_DATA_ADD: |
||
| 68 | if ($ownActivity) { |
||
| 69 | $parsedSubject = $this->l10n->t('You have added new data to report {report}'); |
||
| 70 | } else { |
||
| 71 | $parsedSubject = $event->getSubjectParameters()['author'] . $this->l10n->t(' has added new data to report {report}'); |
||
| 72 | } |
||
| 73 | break; |
||
| 74 | case ActivityManager::SUBJECT_DATA_ADD_IMPORT: |
||
| 75 | if ($ownActivity) { |
||
| 76 | $parsedSubject = $this->l10n->t('You have imported data in report {report}'); |
||
| 77 | } else { |
||
| 78 | $parsedSubject = $event->getSubjectParameters()['author'] . $this->l10n->t(' has importet data in report {report}'); |
||
| 79 | } |
||
| 80 | break; |
||
| 81 | case ActivityManager::SUBJECT_DATA_ADD_API: |
||
| 82 | $parsedSubject = $this->l10n->t('New data was add via API to report {report}'); |
||
| 83 | break; |
||
| 84 | case ActivityManager::SUBJECT_DATA_ADD_DATALOAD: |
||
| 85 | $parsedSubject = $this->l10n->t('New data was add via dataload to report {report}'); |
||
| 86 | break; |
||
| 87 | } |
||
| 88 | |||
| 89 | $event->setRichSubject( |
||
| 90 | $parsedSubject, |
||
| 91 | ['report' => [ |
||
| 92 | 'type' => 'highlight', |
||
| 93 | 'id' => $event->getObjectId(), |
||
| 94 | 'name' => basename($event->getObjectName()), |
||
| 95 | 'link' => $this->Url($event->getObjectId()), |
||
| 96 | ]] |
||
| 97 | ); |
||
| 98 | |||
| 99 | $event->setParsedSubject($parsedSubject) |
||
| 100 | ->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath($event->getApp(), 'app-dark.svg'))); |
||
| 101 | return $event; |
||
| 102 | } |
||
| 108 | } |