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