| Conditions | 10 |
| Paths | 11 |
| Total Lines | 94 |
| 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 |
||
| 87 | public function prepare(INotification $notification, string $languageCode): INotification { |
||
| 88 | $l = $this->l10nFactory->get('deck', $languageCode); |
||
| 89 | if ($notification->getApp() !== 'deck') { |
||
| 90 | throw new \InvalidArgumentException(); |
||
| 91 | } |
||
| 92 | $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('deck', 'deck-dark.svg'))); |
||
| 93 | $params = $notification->getSubjectParameters(); |
||
| 94 | |||
| 95 | switch ($notification->getSubject()) { |
||
| 96 | case 'card-assigned': |
||
| 97 | $cardId = $notification->getObjectId(); |
||
| 98 | $boardId = $this->cardMapper->findBoardId($cardId); |
||
| 99 | $initiator = $this->userManager->get($params[2]); |
||
| 100 | if ($initiator !== null) { |
||
| 101 | $dn = $initiator->getDisplayName(); |
||
| 102 | } else { |
||
| 103 | $dn = $params[2]; |
||
| 104 | } |
||
| 105 | $notification->setParsedSubject( |
||
| 106 | (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', [$params[0], $params[1], $dn]) |
||
| 107 | ); |
||
| 108 | $notification->setRichSubject( |
||
| 109 | (string) $l->t('{user} has assigned the card "%s" on "%s" to you.', [$params[0], $params[1]]), |
||
| 110 | [ |
||
| 111 | 'user' => [ |
||
| 112 | 'type' => 'user', |
||
| 113 | 'id' => $params[2], |
||
| 114 | 'name' => $dn, |
||
| 115 | ] |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); |
||
| 119 | break; |
||
| 120 | case 'card-overdue': |
||
| 121 | $cardId = $notification->getObjectId(); |
||
| 122 | $boardId = $this->cardMapper->findBoardId($cardId); |
||
| 123 | $notification->setParsedSubject( |
||
| 124 | (string) $l->t('The card "%s" on "%s" has reached its due date.', $params) |
||
| 125 | ); |
||
| 126 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); |
||
| 127 | break; |
||
| 128 | case 'card-comment-mentioned': |
||
| 129 | $cardId = $notification->getObjectId(); |
||
| 130 | $boardId = $this->cardMapper->findBoardId($cardId); |
||
| 131 | $initiator = $this->userManager->get($params[2]); |
||
| 132 | if ($initiator !== null) { |
||
| 133 | $dn = $initiator->getDisplayName(); |
||
| 134 | } else { |
||
| 135 | $dn = $params[2]; |
||
| 136 | } |
||
| 137 | $notification->setParsedSubject( |
||
| 138 | (string) $l->t('%s has mentioned you in a comment on "%s".', [$dn, $params[0]]) |
||
| 139 | ); |
||
| 140 | $notification->setRichSubject( |
||
| 141 | (string) $l->t('{user} has mentioned you in a comment on "%s".', [$params[0]]), |
||
| 142 | [ |
||
| 143 | 'user' => [ |
||
| 144 | 'type' => 'user', |
||
| 145 | 'id' => $params[2], |
||
| 146 | 'name' => $dn, |
||
| 147 | ] |
||
| 148 | ] |
||
| 149 | ); |
||
| 150 | if ($notification->getMessage() === '{message}') { |
||
| 151 | $notification->setParsedMessage($notification->getMessageParameters()['message']); |
||
| 152 | } |
||
| 153 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); |
||
| 154 | break; |
||
| 155 | case 'board-shared': |
||
| 156 | $boardId = $notification->getObjectId(); |
||
| 157 | $initiator = $this->userManager->get($params[1]); |
||
| 158 | if ($initiator !== null) { |
||
| 159 | $dn = $initiator->getDisplayName(); |
||
| 160 | } else { |
||
| 161 | $dn = $params[1]; |
||
| 162 | } |
||
| 163 | $notification->setParsedSubject( |
||
| 164 | (string) $l->t('The board "%s" has been shared with you by %s.', [$params[0], $dn]) |
||
| 165 | ); |
||
| 166 | $notification->setRichSubject( |
||
| 167 | (string) $l->t('{user} has shared the board %s with you.', [$params[0]]), |
||
| 168 | [ |
||
| 169 | 'user' => [ |
||
| 170 | 'type' => 'user', |
||
| 171 | 'id' => $params[1], |
||
| 172 | 'name' => $dn, |
||
| 173 | ] |
||
| 174 | ] |
||
| 175 | ); |
||
| 176 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '/'); |
||
| 177 | break; |
||
| 178 | } |
||
| 179 | return $notification; |
||
| 180 | } |
||
| 181 | } |
||
| 182 |