| Conditions | 27 |
| Paths | 97 |
| Total Lines | 104 |
| Code Lines | 81 |
| Lines | 37 |
| Ratio | 35.58 % |
| 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 |
||
| 169 | public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
||
| 170 | $parsedParameters = $this->getParameters($event); |
||
| 171 | |||
| 172 | if ($event->getSubject() === 'created_self') { |
||
| 173 | $subject = $this->l->t('You created {file}'); |
||
| 174 | if ($this->activityManager->getRequirePNG()) { |
||
| 175 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
||
| 176 | } else { |
||
| 177 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
||
| 178 | } |
||
| 179 | } else if ($event->getSubject() === 'created_by') { |
||
| 180 | $subject = $this->l->t('{user} created {file}'); |
||
| 181 | if ($this->activityManager->getRequirePNG()) { |
||
| 182 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
||
| 183 | } else { |
||
| 184 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
||
| 185 | } |
||
| 186 | } else if ($event->getSubject() === 'created_public') { |
||
| 187 | $subject = $this->l->t('{file} was created in a public folder'); |
||
| 188 | if ($this->activityManager->getRequirePNG()) { |
||
| 189 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.png'))); |
||
| 190 | } else { |
||
| 191 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg'))); |
||
| 192 | } |
||
| 193 | } else if ($event->getSubject() === 'changed_self') { |
||
| 194 | $subject = $this->l->t('You changed {file}'); |
||
| 195 | if ($this->activityManager->getRequirePNG()) { |
||
| 196 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
||
| 197 | } else { |
||
| 198 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
||
| 199 | } |
||
| 200 | } else if ($event->getSubject() === 'changed_by') { |
||
| 201 | $subject = $this->l->t('{user} changed {file}'); |
||
| 202 | if ($this->activityManager->getRequirePNG()) { |
||
| 203 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
||
| 204 | } else { |
||
| 205 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
||
| 206 | } |
||
| 207 | } else if ($event->getSubject() === 'deleted_self') { |
||
| 208 | $subject = $this->l->t('You deleted {file}'); |
||
| 209 | if ($this->activityManager->getRequirePNG()) { |
||
| 210 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
||
| 211 | } else { |
||
| 212 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
||
| 213 | } |
||
| 214 | } else if ($event->getSubject() === 'deleted_by') { |
||
| 215 | $subject = $this->l->t('{user} deleted {file}'); |
||
| 216 | if ($this->activityManager->getRequirePNG()) { |
||
| 217 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.png'))); |
||
| 218 | } else { |
||
| 219 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg'))); |
||
| 220 | } |
||
| 221 | } else if ($event->getSubject() === 'restored_self') { |
||
| 222 | $subject = $this->l->t('You restored {file}'); |
||
| 223 | View Code Duplication | } else if ($event->getSubject() === 'restored_by') { |
|
| 224 | $subject = $this->l->t('{user} restored {file}'); |
||
| 225 | } else if ($event->getSubject() === 'renamed_self') { |
||
| 226 | $subject = $this->l->t('You renamed {oldfile} to {newfile}'); |
||
| 227 | if ($this->activityManager->getRequirePNG()) { |
||
| 228 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
||
| 229 | } else { |
||
| 230 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
||
| 231 | } |
||
| 232 | } else if ($event->getSubject() === 'renamed_by') { |
||
| 233 | $subject = $this->l->t('{user} renamed {oldfile} to {newfile}'); |
||
| 234 | if ($this->activityManager->getRequirePNG()) { |
||
| 235 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
||
| 236 | } else { |
||
| 237 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
||
| 238 | } |
||
| 239 | } else if ($event->getSubject() === 'moved_self') { |
||
| 240 | $subject = $this->l->t('You moved {oldfile} to {newfile}'); |
||
| 241 | if ($this->activityManager->getRequirePNG()) { |
||
| 242 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
||
| 243 | } else { |
||
| 244 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
||
| 245 | } |
||
| 246 | } else if ($event->getSubject() === 'moved_by') { |
||
| 247 | $subject = $this->l->t('{user} moved {oldfile} to {newfile}'); |
||
| 248 | if ($this->activityManager->getRequirePNG()) { |
||
| 249 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.png'))); |
||
| 250 | } else { |
||
| 251 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg'))); |
||
| 252 | } |
||
| 253 | } else { |
||
| 254 | throw new \InvalidArgumentException(); |
||
| 255 | } |
||
| 256 | |||
| 257 | View Code Duplication | if (!isset($parsedParameters['user'])) { |
|
| 258 | // External user via public link share |
||
| 259 | $subject = str_replace('{user}', $this->activityLang->t('"remote user"'), $subject); |
||
| 260 | } |
||
| 261 | |||
| 262 | $this->setSubjects($event, $subject, $parsedParameters); |
||
| 263 | |||
| 264 | $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
||
| 265 | |||
| 266 | if ($event->getChildEvent() === null) { |
||
| 267 | // Couldn't group by file, maybe we can group by user |
||
| 268 | $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent); |
||
| 269 | } |
||
| 270 | |||
| 271 | return $event; |
||
| 272 | } |
||
| 273 | |||
| 399 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.