Conditions | 14 |
Paths | 29 |
Total Lines | 41 |
Code Lines | 21 |
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 |
||
79 | public function handle(Event $event): void { |
||
80 | if (($user = $this->userSession->getUser()) === null) { |
||
81 | // Without user context we can't do anything |
||
82 | return; |
||
83 | } |
||
84 | |||
85 | if ($event instanceof CalendarObjectCreatedEvent || $event instanceof CalendarObjectUpdatedEvent) { |
||
86 | // users: href => principal:principals/users/admin |
||
87 | foreach ($event->getShares() as $share) { |
||
88 | if (!isset($share['href'])) { |
||
89 | continue; |
||
90 | } |
||
91 | $this->emitFromUri($share['href'], $user); |
||
92 | } |
||
93 | |||
94 | // emit interaction for email attendees as well |
||
95 | if (isset($event->getObjectData()['calendardata'])) { |
||
96 | try { |
||
97 | $calendar = Reader::read($event->getObjectData()['calendardata']); |
||
98 | if ($calendar->VEVENT) { |
||
99 | foreach ($calendar->VEVENT as $calendarEvent) { |
||
100 | $this->emitFromObject($calendarEvent, $user); |
||
101 | } |
||
102 | } |
||
103 | } catch (Throwable $e) { |
||
104 | $this->logger->warning('Could not read calendar data for interaction events: ' . $e->getMessage(), [ |
||
105 | 'exception' => $e, |
||
106 | ]); |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
111 | if ($event instanceof CalendarShareUpdatedEvent && !empty($event->getAdded())) { |
||
112 | // group: href => principal:principals/groups/admin |
||
113 | // users: href => principal:principals/users/admin |
||
114 | foreach ($event->getAdded() as $added) { |
||
115 | if (!isset($added['href'])) { |
||
116 | // Nothing to work with |
||
117 | continue; |
||
118 | } |
||
119 | $this->emitFromUri($added['href'], $user); |
||
120 | } |
||
178 |