| Conditions | 9 |
| Paths | 17 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 declare(strict_types=1); |
||
| 111 | public function prepare(INotification $notification, string $languageCode): INotification { |
||
| 112 | if ($notification->getApp() !== 'circles') { |
||
| 113 | throw new InvalidArgumentException(); |
||
| 114 | } |
||
| 115 | |||
| 116 | $l10n = OC::$server->getL10N(Application::APP_NAME, $languageCode); |
||
| 117 | |||
| 118 | $notification->setIcon( |
||
| 119 | $this->url->getAbsoluteURL($this->url->imagePath('circles', 'black_circle.svg')) |
||
| 120 | ); |
||
| 121 | $params = $notification->getSubjectParameters(); |
||
| 122 | |||
| 123 | switch ($notification->getSubject()) { |
||
| 124 | case 'invitation': |
||
| 125 | $notification->setParsedSubject( |
||
| 126 | $l10n->t('You have been invited by %1$s into the Circle "%2$s"', $params) |
||
| 127 | ); |
||
| 128 | break; |
||
| 129 | |||
| 130 | case 'member_new': |
||
| 131 | $notification->setParsedSubject( |
||
| 132 | $l10n->t('You are now a member of the Circle "%2$s"', $params) |
||
| 133 | ); |
||
| 134 | break; |
||
| 135 | |||
| 136 | case 'request_new': |
||
| 137 | $notification->setParsedSubject( |
||
| 138 | $l10n->t('%1$s sent a request to be a member of the Circle "%2$s"', $params) |
||
| 139 | ); |
||
| 140 | break; |
||
| 141 | |||
| 142 | default: |
||
| 143 | throw new InvalidArgumentException(); |
||
| 144 | } |
||
| 145 | |||
| 146 | |||
| 147 | foreach ($notification->getActions() as $action) { |
||
| 148 | switch ($action->getLabel()) { |
||
| 149 | case 'accept': |
||
| 150 | $action->setParsedLabel((string)$l10n->t('Accept')) |
||
| 151 | ->setPrimary(true); |
||
| 152 | break; |
||
| 153 | |||
| 154 | case 'refuse': |
||
| 155 | $action->setParsedLabel((string)$l10n->t('Refuse')); |
||
| 156 | break; |
||
| 157 | |||
| 158 | case 'leave': |
||
| 159 | $action->setParsedLabel((string)$l10n->t('Leave the circle')); |
||
| 160 | break; |
||
| 161 | } |
||
| 162 | |||
| 163 | $notification->addParsedAction($action); |
||
| 164 | } |
||
| 165 | |||
| 166 | return $notification; |
||
| 167 | |||
| 168 | } |
||
| 169 | |||
| 171 |