| Conditions | 9 |
| Paths | 9 |
| Total Lines | 92 |
| 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 |
||
| 67 | public function prepare(INotification $notification, $languageCode) { |
||
| 68 | $l = $this->l10nFactory->get('deck', $languageCode); |
||
| 69 | if ($notification->getApp() !== 'deck') { |
||
| 70 | throw new \InvalidArgumentException(); |
||
| 71 | } |
||
| 72 | $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('deck', 'deck-dark.svg'))); |
||
| 73 | $params = $notification->getSubjectParameters(); |
||
| 74 | |||
| 75 | switch ($notification->getSubject()) { |
||
| 76 | case 'card-assigned': |
||
| 77 | $cardId = $notification->getObjectId(); |
||
| 78 | $boardId = $this->cardMapper->findBoardId($cardId); |
||
| 79 | $initiator = $this->userManager->get($params[2]); |
||
| 80 | if ($initiator !== null) { |
||
| 81 | $dn = $initiator->getDisplayName(); |
||
| 82 | } else { |
||
| 83 | $dn = $params[2]; |
||
| 84 | } |
||
| 85 | $notification->setParsedSubject( |
||
| 86 | (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', [$params[0], $params[1], $dn]) |
||
| 87 | ); |
||
| 88 | $notification->setRichSubject( |
||
| 89 | (string) $l->t('{user} has assigned the card "%s" on "%s" to you.', [$params[0], $params[1]]), |
||
| 90 | [ |
||
| 91 | 'user' => [ |
||
| 92 | 'type' => 'user', |
||
| 93 | 'id' => $params[2], |
||
| 94 | 'name' => $dn, |
||
| 95 | ] |
||
| 96 | ] |
||
| 97 | ); |
||
| 98 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); |
||
| 99 | break; |
||
| 100 | case 'card-overdue': |
||
| 101 | $cardId = $notification->getObjectId(); |
||
| 102 | $boardId = $this->cardMapper->findBoardId($cardId); |
||
| 103 | $notification->setParsedSubject( |
||
| 104 | (string) $l->t('The card "%s" on "%s" has reached its due date.', $params) |
||
| 105 | ); |
||
| 106 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); |
||
| 107 | break; |
||
| 108 | case 'card-comment-mentioned': |
||
| 109 | $cardId = $notification->getObjectId(); |
||
| 110 | $boardId = $this->cardMapper->findBoardId($cardId); |
||
| 111 | $initiator = $this->userManager->get($params[2]); |
||
| 112 | if ($initiator !== null) { |
||
| 113 | $dn = $initiator->getDisplayName(); |
||
| 114 | } else { |
||
| 115 | $dn = $params[2]; |
||
| 116 | } |
||
| 117 | $notification->setParsedSubject( |
||
| 118 | (string) $l->t('%s has mentioned in a comment on "%s".', [$dn, $params[0]]) |
||
| 119 | ); |
||
| 120 | $notification->setRichSubject( |
||
| 121 | (string) $l->t('{user} has mentioned in a comment on "%s".', [$params[0]]), |
||
| 122 | [ |
||
| 123 | 'user' => [ |
||
| 124 | 'type' => 'user', |
||
| 125 | 'id' => $params[2], |
||
| 126 | 'name' => $dn, |
||
| 127 | ] |
||
| 128 | ] |
||
| 129 | ); |
||
| 130 | $notification->setParsedMessage($notification->getMessage()); |
||
| 131 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); |
||
| 132 | break; |
||
| 133 | case 'board-shared': |
||
| 134 | $boardId = $notification->getObjectId(); |
||
| 135 | $initiator = $this->userManager->get($params[1]); |
||
| 136 | if ($initiator !== null) { |
||
| 137 | $dn = $initiator->getDisplayName(); |
||
| 138 | } else { |
||
| 139 | $dn = $params[1]; |
||
| 140 | } |
||
| 141 | $notification->setParsedSubject( |
||
| 142 | (string) $l->t('The board "%s" has been shared with you by %s.', [$params[0], $dn]) |
||
| 143 | ); |
||
| 144 | $notification->setRichSubject( |
||
| 145 | (string) $l->t('{user} has shared the board %s with you.', [$params[0]]), |
||
| 146 | [ |
||
| 147 | 'user' => [ |
||
| 148 | 'type' => 'user', |
||
| 149 | 'id' => $params[1], |
||
| 150 | 'name' => $dn, |
||
| 151 | ] |
||
| 152 | ] |
||
| 153 | ); |
||
| 154 | $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '/'); |
||
| 155 | break; |
||
| 156 | } |
||
| 157 | return $notification; |
||
| 158 | } |
||
| 159 | } |
||
| 160 |