| Conditions | 10 |
| Paths | 9 |
| Total Lines | 26 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 68 | public function handle(Event $event): void { |
||
| 69 | if (($user = $this->userManager->getUser()) === null) { |
||
| 70 | // Without user context we can't do anything |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($event instanceof CalendarObjectCreatedEvent || $event instanceof CalendarObjectUpdatedEvent) { |
||
| 75 | // users: href => principal:principals/users/admin |
||
| 76 | // TODO: parse (email) attendees from the VCARD |
||
| 77 | foreach ($event->getShares() as $share) { |
||
| 78 | if (!isset($share['href'])) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | $this->emitFromUri($share['href'], $user); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($event instanceof CalendarShareUpdatedEvent && !empty($event->getAdded())) { |
||
| 86 | // group: href => principal:principals/groups/admin |
||
| 87 | // users: href => principal:principals/users/admin |
||
| 88 | foreach ($event->getAdded() as $added) { |
||
| 89 | if (!isset($added['href'])) { |
||
| 90 | // Nothing to work with |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | $this->emitFromUri($added['href'], $user); |
||
| 94 | } |
||
| 118 |