| Conditions | 11 |
| Paths | 11 |
| Total Lines | 72 |
| 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 |
||
| 40 | * @param string $languageCode The code of the language that should be used to prepare the notification |
||
| 41 | */ |
||
| 42 | public function prepare(INotification $notification, string $languageCode): INotification { |
||
| 43 | if ($notification->getApp() !== 'passman') { |
||
| 44 | // Not my app => throw |
||
| 45 | throw new \InvalidArgumentException(); |
||
| 46 | } |
||
| 47 | |||
| 48 | // Read the language from the notification |
||
| 49 | $l = $this->factory->get('passman', $languageCode); |
||
| 50 | |||
| 51 | switch ($notification->getSubject()) { |
||
| 52 | // Deal with known subjects |
||
| 53 | case 'credential_expired': |
||
| 54 | $notification->setParsedSubject( |
||
| 55 | (string)$l->t('Your credential "%s" expired, click here to update the credential.', $notification->getSubjectParameters()) |
||
| 56 | ); |
||
| 57 | |||
| 58 | // Deal with the actions for a known subject |
||
| 59 | foreach ($notification->getActions() as $action) { |
||
| 60 | switch ($action->getLabel()) { |
||
| 61 | case 'remind': |
||
| 62 | $action->setParsedLabel( |
||
| 63 | (string)$l->t('Remind me later') |
||
| 64 | ); |
||
| 65 | break; |
||
| 66 | |||
| 67 | case 'ignore': |
||
| 68 | $action->setParsedLabel( |
||
| 69 | (string)$l->t('Ignore') |
||
| 70 | ); |
||
| 71 | break; |
||
| 72 | } |
||
| 73 | |||
| 74 | $notification->addParsedAction($action); |
||
| 75 | } |
||
| 76 | return $notification; |
||
| 77 | |||
| 78 | |||
| 79 | case 'credential_shared': |
||
| 80 | $notification->setParsedSubject( |
||
| 81 | (string)$l->t('%s shared "%s" with you. Click here to accept', $notification->getSubjectParameters()) |
||
| 82 | ); |
||
| 83 | |||
| 84 | // Deal with the actions for a known subject |
||
| 85 | foreach ($notification->getActions() as $action) { |
||
| 86 | switch ($action->getLabel()) { |
||
| 87 | case 'decline': |
||
| 88 | $action->setParsedLabel( |
||
| 89 | (string)$l->t('Decline') |
||
| 90 | ); |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | |||
| 94 | $notification->addParsedAction($action); |
||
| 95 | } |
||
| 96 | return $notification; |
||
| 97 | |||
| 98 | case 'credential_share_denied': |
||
| 99 | $notification->setParsedSubject( |
||
| 100 | (string)$l->t('%s has declined your share request for "%s".', $notification->getSubjectParameters()) |
||
| 101 | ); |
||
| 102 | return $notification; |
||
| 103 | |||
| 104 | case 'credential_share_accepted': |
||
| 105 | $notification->setParsedSubject( |
||
| 106 | (string)$l->t('%s has accepted your share request for "%s".', $notification->getSubjectParameters()) |
||
| 107 | ); |
||
| 108 | return $notification; |
||
| 109 | default: |
||
| 110 | // Unknown subject => Unknown notification => throw |
||
| 111 | throw new \InvalidArgumentException(); |
||
| 112 | } |
||
| 133 |