| Conditions | 36 |
| Paths | 53 |
| Total Lines | 98 |
| Code Lines | 75 |
| Lines | 12 |
| Ratio | 12.24 % |
| 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 |
||
| 155 | protected function getParameters(IEvent $event) { |
||
| 156 | $subject = $event->getSubject(); |
||
| 157 | $parameters = $event->getSubjectParameters(); |
||
| 158 | |||
| 159 | // Nextcloud 13+ |
||
| 160 | if (isset($parameters['calendar'])) { |
||
| 161 | switch ($subject) { |
||
| 162 | case self::SUBJECT_ADD: |
||
| 163 | case self::SUBJECT_ADD . '_self': |
||
| 164 | case self::SUBJECT_DELETE: |
||
| 165 | case self::SUBJECT_DELETE . '_self': |
||
| 166 | case self::SUBJECT_UPDATE: |
||
| 167 | case self::SUBJECT_UPDATE . '_self': |
||
| 168 | case self::SUBJECT_SHARE_USER: |
||
| 169 | case self::SUBJECT_UNSHARE_USER: |
||
| 170 | case self::SUBJECT_UNSHARE_USER . '_self': |
||
| 171 | return [ |
||
| 172 | 'actor' => $this->generateUserParameter($parameters['actor']), |
||
| 173 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 174 | ]; |
||
| 175 | case self::SUBJECT_SHARE_USER . '_you': |
||
| 176 | case self::SUBJECT_UNSHARE_USER . '_you': |
||
| 177 | return [ |
||
| 178 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 179 | 'user' => $this->generateUserParameter($parameters['user']), |
||
| 180 | ]; |
||
| 181 | case self::SUBJECT_SHARE_USER . '_by': |
||
| 182 | case self::SUBJECT_UNSHARE_USER . '_by': |
||
| 183 | return [ |
||
| 184 | 'actor' => $this->generateUserParameter($parameters['actor']), |
||
| 185 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 186 | 'user' => $this->generateUserParameter($parameters['user']), |
||
| 187 | ]; |
||
| 188 | case self::SUBJECT_SHARE_GROUP . '_you': |
||
| 189 | case self::SUBJECT_UNSHARE_GROUP . '_you': |
||
| 190 | return [ |
||
| 191 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 192 | 'group' => $this->generateGroupParameter($parameters['group']), |
||
| 193 | ]; |
||
| 194 | case self::SUBJECT_SHARE_GROUP . '_by': |
||
| 195 | case self::SUBJECT_UNSHARE_GROUP . '_by': |
||
| 196 | return [ |
||
| 197 | 'actor' => $this->generateUserParameter($parameters['actor']), |
||
| 198 | 'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l), |
||
| 199 | 'group' => $this->generateGroupParameter($parameters['group']), |
||
| 200 | ]; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | // Legacy - Do NOT Remove unless necessary |
||
| 205 | // Removing this will break parsing of activities that were created on |
||
| 206 | // Nextcloud 12, so we should keep this as long as it's acceptable. |
||
| 207 | // Otherwise if people upgrade over multiple releases in a short period, |
||
| 208 | // they will get the dead entries in their stream. |
||
| 209 | switch ($subject) { |
||
| 210 | case self::SUBJECT_ADD: |
||
| 211 | case self::SUBJECT_ADD . '_self': |
||
| 212 | case self::SUBJECT_DELETE: |
||
| 213 | case self::SUBJECT_DELETE . '_self': |
||
| 214 | case self::SUBJECT_UPDATE: |
||
| 215 | case self::SUBJECT_UPDATE . '_self': |
||
| 216 | case self::SUBJECT_SHARE_USER: |
||
| 217 | case self::SUBJECT_UNSHARE_USER: |
||
| 218 | case self::SUBJECT_UNSHARE_USER . '_self': |
||
| 219 | return [ |
||
| 220 | 'actor' => $this->generateUserParameter($parameters[0]), |
||
| 221 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 222 | ]; |
||
| 223 | case self::SUBJECT_SHARE_USER . '_you': |
||
| 224 | case self::SUBJECT_UNSHARE_USER . '_you': |
||
| 225 | return [ |
||
| 226 | 'user' => $this->generateUserParameter($parameters[0]), |
||
| 227 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 228 | ]; |
||
| 229 | case self::SUBJECT_SHARE_USER . '_by': |
||
| 230 | View Code Duplication | case self::SUBJECT_UNSHARE_USER . '_by': |
|
| 231 | return [ |
||
| 232 | 'user' => $this->generateUserParameter($parameters[0]), |
||
| 233 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 234 | 'actor' => $this->generateUserParameter($parameters[2]), |
||
| 235 | ]; |
||
| 236 | case self::SUBJECT_SHARE_GROUP . '_you': |
||
| 237 | case self::SUBJECT_UNSHARE_GROUP . '_you': |
||
| 238 | return [ |
||
| 239 | 'group' => $this->generateGroupParameter($parameters[0]), |
||
| 240 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 241 | ]; |
||
| 242 | case self::SUBJECT_SHARE_GROUP . '_by': |
||
| 243 | View Code Duplication | case self::SUBJECT_UNSHARE_GROUP . '_by': |
|
| 244 | return [ |
||
| 245 | 'group' => $this->generateGroupParameter($parameters[0]), |
||
| 246 | 'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]), |
||
| 247 | 'actor' => $this->generateUserParameter($parameters[2]), |
||
| 248 | ]; |
||
| 249 | } |
||
| 250 | |||
| 251 | throw new \InvalidArgumentException(); |
||
| 252 | } |
||
| 253 | } |
||
| 254 |