| Conditions | 10 |
| Paths | 10 |
| Total Lines | 56 |
| Code Lines | 43 |
| 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 |
||
| 54 | public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
||
| 55 | if ($event->getType() !== 'security') { |
||
| 56 | throw new InvalidArgumentException(); |
||
| 57 | } |
||
| 58 | |||
| 59 | $l = $this->l10n->get('settings', $language); |
||
| 60 | |||
| 61 | switch ($event->getSubject()) { |
||
| 62 | case 'twofactor_success': |
||
| 63 | $params = $event->getSubjectParameters(); |
||
| 64 | $event->setParsedSubject($l->t('You successfully logged in using two-factor authentication (%1$s)', [ |
||
| 65 | $params['provider'], |
||
| 66 | ])); |
||
| 67 | if ($this->activityManager->getRequirePNG()) { |
||
| 68 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
||
| 69 | } else { |
||
| 70 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
||
| 71 | } |
||
| 72 | break; |
||
| 73 | case 'twofactor_failed': |
||
| 74 | $params = $event->getSubjectParameters(); |
||
| 75 | $event->setParsedSubject($l->t('A login attempt using two-factor authentication failed (%1$s)', [ |
||
| 76 | $params['provider'], |
||
| 77 | ])); |
||
| 78 | if ($this->activityManager->getRequirePNG()) { |
||
| 79 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
||
| 80 | } else { |
||
| 81 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
||
| 82 | } |
||
| 83 | break; |
||
| 84 | case 'remote_wipe_start': |
||
| 85 | $params = $event->getSubjectParameters(); |
||
| 86 | $event->setParsedSubject($l->t('Remote wipe was started on %1$s', [ |
||
| 87 | $params['name'], |
||
| 88 | ])); |
||
| 89 | if ($this->activityManager->getRequirePNG()) { |
||
| 90 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png'))); |
||
| 91 | } else { |
||
| 92 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg'))); |
||
| 93 | } |
||
| 94 | break; |
||
| 95 | case 'remote_wipe_finish': |
||
| 96 | $params = $event->getSubjectParameters(); |
||
| 97 | $event->setParsedSubject($l->t('Remote wipe has finished on %1$s', [ |
||
| 98 | $params['name'], |
||
| 99 | ])); |
||
| 100 | if ($this->activityManager->getRequirePNG()) { |
||
| 101 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.png'))); |
||
| 102 | } else { |
||
| 103 | $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/delete.svg'))); |
||
| 104 | } |
||
| 105 | break; |
||
| 106 | default: |
||
| 107 | throw new InvalidArgumentException(); |
||
| 108 | } |
||
| 109 | return $event; |
||
| 110 | } |
||
| 113 |