Conditions | 3 |
Paths | 4 |
Total Lines | 60 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
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 |
||
81 | private function saveCalendarEvent( |
||
82 | CStudentPublication $publication, |
||
83 | CStudentPublicationAssignment $assignment, |
||
84 | ResourceLink $courseLink, |
||
85 | Course $course, |
||
86 | ?Session $session, |
||
87 | ?CGroup $group, |
||
88 | ): CCalendarEvent { |
||
89 | $eventTitle = sprintf( |
||
90 | $this->translator->trans('Handing over of task %s'), |
||
91 | $publication->getTitle() |
||
92 | ); |
||
93 | |||
94 | $publicationUrl = $this->router->generate( |
||
95 | 'legacy_main', |
||
96 | [ |
||
97 | 'name' => 'work/work_list.php', |
||
98 | 'cid' => $course->getId(), |
||
99 | 'sid' => $session?->getId(), |
||
100 | 'gid' => $group?->getIid(), |
||
101 | 'id' => $publication->getIid(), |
||
102 | ] |
||
103 | ); |
||
104 | |||
105 | $content = sprintf( |
||
106 | '<div><a href="%s">%s</a></div> %s', |
||
107 | $publicationUrl, |
||
108 | $publication->getTitle(), |
||
109 | $publication->getDescription() |
||
110 | ); |
||
111 | |||
112 | $startDate = new DateTime('now', new DateTimeZone('UTC')); |
||
113 | $endDate = new DateTime('now', new DateTimeZone('UTC')); |
||
114 | |||
115 | if ($expiresOn = $assignment->getExpiresOn()) { |
||
116 | $startDate = clone $expiresOn; |
||
117 | $endDate = clone $expiresOn; |
||
118 | } |
||
119 | |||
120 | $color = CCalendarEvent::COLOR_STUDENT_PUBLICATION; |
||
121 | |||
122 | if ($agendaColors = $this->settingsManager->getSetting('agenda.agenda_colors')) { |
||
123 | $color = $agendaColors['student_publication']; |
||
124 | } |
||
125 | |||
126 | $event = (new CCalendarEvent()) |
||
127 | ->setTitle($eventTitle) |
||
128 | ->setContent($content) |
||
129 | ->setParent($course) |
||
130 | ->setCreator($publication->getCreator()) |
||
131 | ->addLink(clone $courseLink) |
||
132 | ->setStartDate($startDate) |
||
133 | ->setEndDate($endDate) |
||
134 | ->setColor($color) |
||
135 | ; |
||
136 | |||
137 | $this->entityManager->persist($event); |
||
138 | $this->entityManager->flush(); |
||
139 | |||
140 | return $event; |
||
141 | } |
||
212 |