Conditions | 10 |
Paths | 15 |
Total Lines | 34 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
76 | public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { |
||
77 | if ($event->getApp() !== 'dav' || $event->getType() !== 'card') { |
||
78 | throw new \InvalidArgumentException(); |
||
79 | } |
||
80 | |||
81 | $l = $this->languageFactory->get('dav', $language); |
||
82 | |||
83 | if ($this->activityManager->getRequirePNG()) { |
||
84 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/contacts-dark.png'))); |
||
85 | } else { |
||
86 | $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/contacts.svg'))); |
||
87 | } |
||
88 | |||
89 | if ($event->getSubject() === self::SUBJECT_ADD) { |
||
90 | $subject = $l->t('{actor} created contact {card} in addressbook {addressbook}'); |
||
91 | } elseif ($event->getSubject() === self::SUBJECT_ADD . '_self') { |
||
92 | $subject = $l->t('You created contact {card} in addressbook {addressbook}'); |
||
93 | } elseif ($event->getSubject() === self::SUBJECT_DELETE) { |
||
94 | $subject = $l->t('{actor} deleted contact {card} from addressbook {addressbook}'); |
||
95 | } elseif ($event->getSubject() === self::SUBJECT_DELETE . '_self') { |
||
96 | $subject = $l->t('You deleted contact {card} from addressbook {addressbook}'); |
||
97 | } elseif ($event->getSubject() === self::SUBJECT_UPDATE) { |
||
98 | $subject = $l->t('{actor} updated contact {card} in addressbook {addressbook}'); |
||
99 | } elseif ($event->getSubject() === self::SUBJECT_UPDATE . '_self') { |
||
100 | $subject = $l->t('You updated contact {card} in addressbook {addressbook}'); |
||
101 | } else { |
||
102 | throw new \InvalidArgumentException(); |
||
103 | } |
||
104 | |||
105 | $parsedParameters = $this->getParameters($event, $l); |
||
106 | $this->setSubjects($event, $subject, $parsedParameters); |
||
107 | |||
108 | $event = $this->eventMerger->mergeEvents('card', $event, $previousEvent); |
||
109 | return $event; |
||
110 | } |
||
145 |