Conditions | 10 |
Paths | 19 |
Total Lines | 69 |
Code Lines | 37 |
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 |
||
15 | public static function getLpSubscription( |
||
16 | array $lpInfo, |
||
17 | int $studentId, |
||
18 | int $courseId, |
||
19 | int $sessionId = 0, |
||
20 | bool $showTeacherName = true |
||
21 | ): string { |
||
22 | $em = Database::getManager(); |
||
23 | |||
24 | if ($lpInfo['subscribe_users']) { |
||
25 | $itemRepo = $em->getRepository(CItemProperty::class); |
||
26 | $itemProperty = $itemRepo->findByUserSuscribedToItem( |
||
27 | 'learnpath', |
||
28 | $lpInfo['iid'], |
||
29 | $studentId, |
||
30 | $courseId, |
||
31 | $sessionId |
||
32 | ); |
||
33 | |||
34 | if (null === $itemProperty) { |
||
35 | $userGroups = GroupManager::getAllGroupPerUserSubscription($studentId, $courseId); |
||
36 | |||
37 | foreach ($userGroups as $groupInfo) { |
||
38 | $itemProperty = $itemRepo->findByGroupSuscribedToLp( |
||
39 | 'learnpath', |
||
40 | $lpInfo['iid'], |
||
41 | $groupInfo['iid'], |
||
42 | $courseId, |
||
43 | $sessionId |
||
44 | ); |
||
45 | |||
46 | if (null !== $itemProperty) { |
||
47 | break; |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | if (null === $itemProperty) { |
||
53 | return '-'; |
||
54 | } |
||
55 | |||
56 | $formattedDate = api_convert_and_format_date($itemProperty->getInsertDate(), DATE_TIME_FORMAT_LONG); |
||
57 | |||
58 | if ($showTeacherName) { |
||
59 | $insertUser = $itemProperty->getInsertUser()->getId() !== $studentId |
||
60 | ? $itemProperty->getInsertUser()->getCompleteName() |
||
61 | : '-'; |
||
62 | |||
63 | return "$insertUser<br>".Display::tag('small', $formattedDate); |
||
64 | } |
||
65 | |||
66 | return $formattedDate; |
||
67 | } |
||
68 | |||
69 | $subscriptionEvent = Event::findUserSubscriptionToCourse($studentId, $courseId, $sessionId); |
||
|
|||
70 | |||
71 | if (empty($subscriptionEvent)) { |
||
72 | return '-'; |
||
73 | } |
||
74 | |||
75 | $formattedDate = api_convert_and_format_date($subscriptionEvent['default_date'], DATE_TIME_FORMAT_LONG); |
||
76 | |||
77 | if ($showTeacherName) { |
||
78 | $creator = api_get_user_entity($subscriptionEvent['default_user_id']); |
||
79 | |||
80 | return "{$creator->getCompleteName()}<br>".Display::tag('small', $formattedDate); |
||
81 | } |
||
82 | |||
83 | return $formattedDate; |
||
84 | } |
||
215 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.