Conditions | 7 |
Paths | 10 |
Total Lines | 63 |
Code Lines | 44 |
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 |
||
11 | public static function notifyTeachersAndAuthor(PortfolioComment $comment) { |
||
12 | $item = $comment->getItem(); |
||
13 | $course = $item->getCourse(); |
||
14 | $session = $item->getSession(); |
||
15 | |||
16 | |||
17 | $messageSubject = sprintf( |
||
18 | get_lang('PortfolioAlertNewCommentSubject'), |
||
19 | $item->getTitle(true) |
||
20 | ); |
||
21 | $userIdListToSend = []; |
||
22 | $userIdListToSend[] = $comment->getItem()->getUser()->getId(); |
||
23 | |||
24 | $cidreq = api_get_cidreq_params( |
||
25 | $course ? $course->getCode() : '', |
||
|
|||
26 | $session ? $session->getId() : 0 |
||
27 | ); |
||
28 | $commentUrl = api_get_path(WEB_CODE_PATH).'portfolio/index.php?' |
||
29 | .($course ? $cidreq.'&' : '') |
||
30 | .http_build_query(['action' => 'view', 'id' => $item->getId()])."#comment-{$comment->getId()}"; |
||
31 | |||
32 | if ($course) { |
||
33 | $courseInfo = api_get_course_info($course->getCode()); |
||
34 | |||
35 | if (1 !== (int) api_get_course_setting('email_alert_teachers_student_new_comment', $courseInfo)) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | $courseTitle = self::getCourseTitle($course, $session); |
||
40 | $userIdListToSend = array_merge( |
||
41 | $userIdListToSend, |
||
42 | self::getTeacherList($course, $session) |
||
43 | ); |
||
44 | |||
45 | $messageContent = sprintf( |
||
46 | get_lang('CoursePortfolioAlertNewCommentContent'), |
||
47 | $item->getTitle(), |
||
48 | $courseTitle, |
||
49 | $commentUrl |
||
50 | ); |
||
51 | } else { |
||
52 | $messageContent = sprintf( |
||
53 | get_lang('PortfolioAlertNewCommentContent'), |
||
54 | $item->getTitle(), |
||
55 | $commentUrl |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | $messageContent .= '<br><br><figure>' |
||
60 | .'<blockquote>'.$comment->getExcerpt().'</blockquote>' |
||
61 | .'<figcaption>'.$comment->getAuthor()->getCompleteName().'</figcaption>' |
||
62 | .'</figure>'; |
||
63 | |||
64 | foreach ($userIdListToSend as $userIdToSend) { |
||
65 | MessageManager::send_message_simple( |
||
66 | $userIdToSend, |
||
67 | $messageSubject, |
||
68 | $messageContent, |
||
69 | 0, |
||
70 | false, |
||
71 | false, |
||
72 | [], |
||
73 | false |
||
74 | ); |
||
102 | } |