| Conditions | 14 |
| Paths | 20 |
| Total Lines | 50 |
| Lines | 17 |
| Ratio | 34 % |
| 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 |
||
| 122 | protected function getParameters(IEvent $event) { |
||
| 123 | $subject = $event->getSubject(); |
||
| 124 | $parameters = $event->getSubjectParameters(); |
||
| 125 | |||
| 126 | // Nextcloud 13+ |
||
| 127 | if (isset($parameters['calendar'])) { |
||
| 128 | switch ($subject) { |
||
| 129 | case self::SUBJECT_OBJECT_ADD . '_event': |
||
| 130 | case self::SUBJECT_OBJECT_DELETE . '_event': |
||
| 131 | View Code Duplication | case self::SUBJECT_OBJECT_UPDATE . '_event': |
|
| 132 | return [ |
||
| 133 | 'actor' => $this->generateUserParameter($parameters['actor']), |
||
| 134 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 135 | 'event' => $this->generateClassifiedObjectParameter($parameters['object']), |
||
| 136 | ]; |
||
| 137 | case self::SUBJECT_OBJECT_ADD . '_event_self': |
||
| 138 | case self::SUBJECT_OBJECT_DELETE . '_event_self': |
||
| 139 | View Code Duplication | case self::SUBJECT_OBJECT_UPDATE . '_event_self': |
|
| 140 | return [ |
||
| 141 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 142 | 'event' => $this->generateClassifiedObjectParameter($parameters['object']), |
||
| 143 | ]; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | // Legacy - Do NOT Remove unless necessary |
||
| 148 | // Removing this will break parsing of activities that were created on |
||
| 149 | // Nextcloud 12, so we should keep this as long as it's acceptable. |
||
| 150 | // Otherwise if people upgrade over multiple releases in a short period, |
||
| 151 | // they will get the dead entries in their stream. |
||
| 152 | switch ($subject) { |
||
| 153 | case self::SUBJECT_OBJECT_ADD . '_event': |
||
| 154 | case self::SUBJECT_OBJECT_DELETE . '_event': |
||
| 155 | View Code Duplication | case self::SUBJECT_OBJECT_UPDATE . '_event': |
|
| 156 | return [ |
||
| 157 | 'actor' => $this->generateUserParameter($parameters[0]), |
||
| 158 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 159 | 'event' => $this->generateObjectParameter($parameters[2]), |
||
| 160 | ]; |
||
| 161 | case self::SUBJECT_OBJECT_ADD . '_event_self': |
||
| 162 | case self::SUBJECT_OBJECT_DELETE . '_event_self': |
||
| 163 | case self::SUBJECT_OBJECT_UPDATE . '_event_self': |
||
| 164 | return [ |
||
| 165 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 166 | 'event' => $this->generateObjectParameter($parameters[2]), |
||
| 167 | ]; |
||
| 168 | } |
||
| 169 | |||
| 170 | throw new \InvalidArgumentException(); |
||
| 171 | } |
||
| 172 | |||
| 181 |