Conditions | 11 |
Paths | 45 |
Total Lines | 120 |
Code Lines | 76 |
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 |
||
28 | public function up(Schema $schema): void |
||
29 | { |
||
30 | $container = $this->getContainer(); |
||
31 | $doctrine = $container->get('doctrine'); |
||
32 | $em = $doctrine->getManager(); |
||
33 | |||
34 | /** @var Connection $connection */ |
||
35 | $connection = $em->getConnection(); |
||
36 | |||
37 | $eventRepo = $container->get(CCalendarEventRepository::class); |
||
38 | $eventAttachmentRepo = $container->get(CCalendarEventAttachmentRepository::class); |
||
39 | $courseRepo = $container->get(CourseRepository::class); |
||
40 | |||
41 | /** @var Kernel $kernel */ |
||
42 | $kernel = $container->get('kernel'); |
||
43 | $rootPath = $kernel->getProjectDir(); |
||
44 | $admin = $this->getAdmin(); |
||
45 | $oldNewEventIdMap = []; |
||
46 | |||
47 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
48 | |||
49 | /** @var Course $course */ |
||
50 | foreach ($q->toIterable() as $course) { |
||
51 | $courseId = $course->getId(); |
||
52 | $course = $courseRepo->find($courseId); |
||
53 | |||
54 | $sql = "SELECT * FROM c_calendar_event WHERE c_id = {$courseId} |
||
55 | ORDER BY iid"; |
||
56 | $result = $connection->executeQuery($sql); |
||
57 | $events = $result->fetchAllAssociative(); |
||
58 | foreach ($events as $eventData) { |
||
59 | $id = $eventData['iid']; |
||
60 | $oldEventId = $id; |
||
61 | |||
62 | /** @var CCalendarEvent $event */ |
||
63 | $event = $eventRepo->find($id); |
||
64 | if ($event->hasResourceNode()) { |
||
65 | continue; |
||
66 | } |
||
67 | |||
68 | $sql = "SELECT * FROM c_item_property |
||
69 | WHERE tool = 'calendar_event' AND c_id = {$courseId} AND ref = {$id}"; |
||
70 | $result = $connection->executeQuery($sql); |
||
71 | $items = $result->fetchAllAssociative(); |
||
72 | |||
73 | // For some reason this event doesnt have a c_item_property value, |
||
74 | // then we added to the main course and assign the admin as the creator. |
||
75 | if (empty($items)) { |
||
76 | $items[] = [ |
||
77 | 'visibility' => 1, |
||
78 | 'insert_user_id' => $admin->getId(), |
||
79 | 'to_group_id' => 0, |
||
80 | 'session_id' => $eventData['session_id'], |
||
81 | ]; |
||
82 | $this->fixItemProperty('calendar_event', $eventRepo, $course, $admin, $event, $course, $items); |
||
83 | $em->persist($event); |
||
84 | $em->flush(); |
||
85 | |||
86 | continue; |
||
87 | } |
||
88 | |||
89 | // Assign parent. |
||
90 | $parent = null; |
||
91 | if (!empty($eventData['parent_event_id'])) { |
||
92 | $parent = $eventRepo->find($eventData['parent_event_id']); |
||
93 | } |
||
94 | if (null === $parent) { |
||
95 | $parent = $course; |
||
96 | } |
||
97 | |||
98 | if (false === $result) { |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | $this->fixItemProperty('calendar_event', $eventRepo, $course, $admin, $event, $parent); |
||
103 | |||
104 | $em->persist($event); |
||
105 | $em->flush(); |
||
106 | |||
107 | $newEventId = $event->getId(); |
||
|
|||
108 | $oldNewEventIdMap[$oldEventId] = $newEventId; |
||
109 | } |
||
110 | |||
111 | $sql = "SELECT * FROM c_calendar_event_attachment WHERE c_id = {$courseId} |
||
112 | ORDER BY iid"; |
||
113 | $result = $connection->executeQuery($sql); |
||
114 | $attachments = $result->fetchAllAssociative(); |
||
115 | foreach ($attachments as $attachmentData) { |
||
116 | $id = $attachmentData['iid']; |
||
117 | $attachmentPath = $attachmentData['path']; |
||
118 | $fileName = $attachmentData['filename']; |
||
119 | |||
120 | /** @var CCalendarEventAttachment $attachment */ |
||
121 | $attachment = $eventAttachmentRepo->find($id); |
||
122 | if ($attachment->hasResourceNode()) { |
||
123 | continue; |
||
124 | } |
||
125 | $parent = $attachment->getEvent(); |
||
126 | $result = $this->fixItemProperty( |
||
127 | 'calendar_event_attachment', |
||
128 | $eventRepo, |
||
129 | $course, |
||
130 | $admin, |
||
131 | $attachment, |
||
132 | $parent |
||
133 | ); |
||
134 | |||
135 | if (false === $result) { |
||
136 | continue; |
||
137 | } |
||
138 | |||
139 | $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/calendar/'.$attachmentPath; |
||
140 | error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...'); |
||
141 | $this->addLegacyFileToResource($filePath, $eventAttachmentRepo, $attachment, $id, $fileName); |
||
142 | $em->persist($attachment); |
||
143 | $em->flush(); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | $this->updateAgendaReminders($oldNewEventIdMap, $em); |
||
148 | } |
||
166 |
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.