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