| Conditions | 10 |
| Paths | 23 |
| Total Lines | 82 |
| Code Lines | 59 |
| 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 |
||
| 28 | public function up(Schema $schema): void |
||
| 29 | { |
||
| 30 | $container = $this->getContainer(); |
||
| 31 | $doctrine = $container->get('doctrine'); |
||
| 32 | $em = $doctrine->getManager(); |
||
| 33 | /** @var Connection $connection */ |
||
| 34 | $connection = $em->getConnection(); |
||
| 35 | |||
| 36 | $urlRepo = $em->getRepository(AccessUrlRepository::class); |
||
| 37 | $eventRepo = $container->get(CCalendarEventRepository::class); |
||
| 38 | $eventAttachmentRepo = $container->get(CCalendarEventAttachmentRepository::class); |
||
| 39 | $courseRepo = $container->get(CourseRepository::class); |
||
| 40 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 41 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 42 | $userRepo = $container->get(UserRepository::class); |
||
| 43 | |||
| 44 | /** @var Kernel $kernel */ |
||
| 45 | $kernel = $container->get('kernel'); |
||
| 46 | $rootPath = $kernel->getProjectDir(); |
||
| 47 | $admin = $this->getAdmin(); |
||
| 48 | $urls = $urlRepo->findAll(); |
||
| 49 | |||
| 50 | /** @var AccessUrl $url */ |
||
| 51 | foreach ($urls as $url) { |
||
| 52 | $accessUrlRelCourses = $url->getCourses(); |
||
| 53 | /** @var AccessUrlRelCourse $accessUrlRelCourse */ |
||
| 54 | foreach ($accessUrlRelCourses as $accessUrlRelCourse) { |
||
| 55 | $counter = 1; |
||
| 56 | $course = $accessUrlRelCourse->getCourse(); |
||
| 57 | $courseId = $course->getId(); |
||
| 58 | $courseCode = $course->getCode(); |
||
| 59 | $course = $courseRepo->find($courseId); |
||
| 60 | |||
| 61 | $sql = "SELECT * FROM c_calendar_event WHERE c_id = $courseId |
||
| 62 | ORDER BY iid"; |
||
| 63 | $result = $connection->executeQuery($sql); |
||
| 64 | $events = $result->fetchAllAssociative(); |
||
| 65 | foreach ($events as $event) { |
||
| 66 | $id = $event['iid']; |
||
| 67 | /** @var CCalendarEvent $event */ |
||
| 68 | $event = $eventRepo->find($id); |
||
| 69 | if ($event->hasResourceNode()) { |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | $sql = "SELECT * FROM c_item_property |
||
| 73 | WHERE tool = 'calendar_event' AND c_id = $courseId AND ref = $id"; |
||
| 74 | $result = $connection->executeQuery($sql); |
||
| 75 | $items = $result->fetchAllAssociative(); |
||
| 76 | |||
| 77 | // For some reason this document doesnt have a c_item_property value. |
||
| 78 | if (empty($items)) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | $parent = null; |
||
| 82 | if (!empty($event['parent_event_id'])) { |
||
| 83 | $parent = $eventRepo->find($event['parent_event_id']); |
||
| 84 | } |
||
| 85 | if (null === $parent) { |
||
| 86 | $parent = $course; |
||
| 87 | } |
||
| 88 | $this->fixItemProperty($eventRepo, $course, $admin, $event, $parent, $items); |
||
| 89 | } |
||
| 90 | |||
| 91 | $sql = "SELECT * FROM c_calendar_event_attachment WHERE c_id = $courseId |
||
| 92 | ORDER BY iid"; |
||
| 93 | $result = $connection->executeQuery($sql); |
||
| 94 | $events = $result->fetchAllAssociative(); |
||
| 95 | foreach ($events as $event) { |
||
| 96 | $id = $event['iid']; |
||
| 97 | $attachmentPath = $event['filename']; |
||
| 98 | /** @var CCalendarEventAttachment $event */ |
||
| 99 | $event = $eventAttachmentRepo->find($id); |
||
| 100 | if ($event->hasResourceNode()) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | $sql = "SELECT * FROM c_item_property |
||
| 104 | WHERE tool = 'calendar_event_attachment' AND c_id = $courseId AND ref = $id"; |
||
| 105 | $result = $connection->executeQuery($sql); |
||
| 106 | $items = $result->fetchAllAssociative(); |
||
| 107 | $this->fixItemProperty($eventAttachmentRepo, $event, $parent, $items); |
||
| 108 | $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/calendar/'.$attachmentPath; |
||
| 109 | $this->addLegacyFileToResource($filePath, $eventAttachmentRepo, $event, $id); |
||
| 110 | } |
||
| 119 |