| Conditions | 8 |
| Paths | 17 |
| Total Lines | 89 |
| Code Lines | 61 |
| 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 |
||
| 27 | public function up(Schema $schema): void |
||
| 28 | { |
||
| 29 | $container = $this->getContainer(); |
||
| 30 | $doctrine = $container->get('doctrine'); |
||
| 31 | $em = $doctrine->getManager(); |
||
| 32 | /** @var Connection $connection */ |
||
| 33 | $connection = $em->getConnection(); |
||
| 34 | |||
| 35 | $announcementRepo = $container->get(CAnnouncementRepository::class); |
||
| 36 | $announcementAttachmentRepo = $container->get(CAnnouncementAttachmentRepository::class); |
||
| 37 | |||
| 38 | $courseRepo = $container->get(CourseRepository::class); |
||
| 39 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 40 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 41 | $userRepo = $container->get(UserRepository::class); |
||
| 42 | |||
| 43 | /** @var Kernel $kernel */ |
||
| 44 | $kernel = $container->get('kernel'); |
||
| 45 | $rootPath = $kernel->getProjectDir(); |
||
| 46 | |||
| 47 | $admin = $this->getAdmin(); |
||
| 48 | |||
| 49 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 50 | foreach ($q->toIterable() as $course) { |
||
| 51 | $courseId = $course->getId(); |
||
| 52 | $course = $courseRepo->find($courseId); |
||
| 53 | |||
| 54 | $sql = "SELECT * FROM c_announcement WHERE c_id = $courseId |
||
| 55 | ORDER BY iid"; |
||
| 56 | $result = $connection->executeQuery($sql); |
||
| 57 | $items = $result->fetchAllAssociative(); |
||
| 58 | foreach ($items as $itemData) { |
||
| 59 | $id = $itemData['iid']; |
||
| 60 | /** @var CQuiz $resource */ |
||
| 61 | $resource = $announcementRepo->find($id); |
||
| 62 | if ($resource->hasResourceNode()) { |
||
| 63 | continue; |
||
| 64 | } |
||
| 65 | |||
| 66 | $result = $this->fixItemProperty( |
||
| 67 | 'announcement', |
||
| 68 | $announcementRepo, |
||
| 69 | $course, |
||
| 70 | $admin, |
||
| 71 | $resource, |
||
| 72 | $course |
||
| 73 | ); |
||
| 74 | |||
| 75 | if (false === $result) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | |||
| 79 | $em->persist($resource); |
||
| 80 | $em->flush(); |
||
| 81 | } |
||
| 82 | |||
| 83 | $sql = "SELECT * FROM c_announcement_attachment WHERE c_id = $courseId |
||
| 84 | ORDER BY iid"; |
||
| 85 | $result = $connection->executeQuery($sql); |
||
| 86 | $items = $result->fetchAllAssociative(); |
||
| 87 | foreach ($items as $itemData) { |
||
| 88 | $id = $itemData['iid']; |
||
| 89 | $path = $itemData['path']; |
||
| 90 | $fileName = $itemData['filename']; |
||
| 91 | /** @var CAnnouncementAttachment $resource */ |
||
| 92 | $resource = $announcementAttachmentRepo->find($id); |
||
| 93 | if ($resource->hasResourceNode()) { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | $result = $this->fixItemProperty( |
||
| 97 | 'announcement_attachment', |
||
| 98 | $announcementAttachmentRepo, |
||
| 99 | $course, |
||
| 100 | $admin, |
||
| 101 | $resource, |
||
| 102 | $course |
||
| 103 | ); |
||
| 104 | |||
| 105 | if (false === $result) { |
||
| 106 | continue; |
||
| 107 | } |
||
| 108 | |||
| 109 | $em->persist($resource); |
||
| 110 | $em->flush(); |
||
| 111 | |||
| 112 | $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/announcements/'.$path; |
||
| 113 | $this->addLegacyFileToResource($filePath, $announcementAttachmentRepo, $resource, $id, $fileName); |
||
| 114 | $em->persist($resource); |
||
| 115 | $em->flush(); |
||
| 116 | } |
||
| 120 |