| Conditions | 11 |
| Paths | 65 |
| Total Lines | 116 |
| Code Lines | 78 |
| 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 |
||
| 29 | public function up(Schema $schema): void |
||
| 30 | { |
||
| 31 | $container = $this->getContainer(); |
||
| 32 | $doctrine = $container->get('doctrine'); |
||
| 33 | $em = $doctrine->getManager(); |
||
| 34 | /** @var Connection $connection */ |
||
| 35 | $connection = $em->getConnection(); |
||
| 36 | |||
| 37 | $forumRepo = $container->get(CForumForumRepository::class); |
||
| 38 | $forumCategoryRepo = $container->get(CForumCategoryRepository::class); |
||
| 39 | $forumThreadRepo = $container->get(CForumThreadRepository::class); |
||
| 40 | |||
| 41 | $courseRepo = $container->get(CourseRepository::class); |
||
| 42 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 43 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 44 | $userRepo = $container->get(UserRepository::class); |
||
| 45 | |||
| 46 | /** @var Kernel $kernel */ |
||
| 47 | $kernel = $container->get('kernel'); |
||
| 48 | $rootPath = $kernel->getProjectDir(); |
||
| 49 | |||
| 50 | $admin = $this->getAdmin(); |
||
| 51 | |||
| 52 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 53 | foreach ($q->toIterable() as $course) { |
||
| 54 | $courseId = $course->getId(); |
||
| 55 | $course = $courseRepo->find($courseId); |
||
| 56 | |||
| 57 | $sql = "SELECT * FROM c_forum_category WHERE c_id = $courseId |
||
| 58 | ORDER BY iid"; |
||
| 59 | $result = $connection->executeQuery($sql); |
||
| 60 | $items = $result->fetchAllAssociative(); |
||
| 61 | foreach ($items as $itemData) { |
||
| 62 | $id = $itemData['iid']; |
||
| 63 | /** @var CForumCategory $resource */ |
||
| 64 | $resource = $forumCategoryRepo->find($id); |
||
| 65 | if ($resource->hasResourceNode()) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | $result = $this->fixItemProperty( |
||
| 69 | 'forum_category', |
||
| 70 | $forumCategoryRepo, |
||
| 71 | $course, |
||
| 72 | $admin, |
||
| 73 | $resource, |
||
| 74 | $course |
||
| 75 | ); |
||
| 76 | |||
| 77 | if (false === $result) { |
||
| 78 | continue; |
||
| 79 | } |
||
| 80 | |||
| 81 | $em->persist($resource); |
||
| 82 | $em->flush(); |
||
| 83 | } |
||
| 84 | |||
| 85 | $em->clear(); |
||
| 86 | |||
| 87 | $sql = "SELECT * FROM c_forum_forum WHERE c_id = $courseId |
||
| 88 | ORDER BY iid"; |
||
| 89 | $result = $connection->executeQuery($sql); |
||
| 90 | $items = $result->fetchAllAssociative(); |
||
| 91 | foreach ($items as $itemData) { |
||
| 92 | $id = $itemData['iid']; |
||
| 93 | /** @var CForumForum $resource */ |
||
| 94 | $resource = $forumRepo->find($id); |
||
| 95 | if ($resource->hasResourceNode()) { |
||
| 96 | continue; |
||
| 97 | } |
||
| 98 | $result = $this->fixItemProperty( |
||
| 99 | 'forum', |
||
| 100 | $forumRepo, |
||
| 101 | $course, |
||
| 102 | $admin, |
||
| 103 | $resource, |
||
| 104 | $course |
||
| 105 | ); |
||
| 106 | |||
| 107 | if (false === $result) { |
||
| 108 | continue; |
||
| 109 | } |
||
| 110 | $em->persist($resource); |
||
| 111 | $em->flush(); |
||
| 112 | } |
||
| 113 | |||
| 114 | $em->clear(); |
||
| 115 | |||
| 116 | $sql = "SELECT * FROM c_forum_thread WHERE c_id = $courseId |
||
| 117 | ORDER BY iid"; |
||
| 118 | $result = $connection->executeQuery($sql); |
||
| 119 | $items = $result->fetchAllAssociative(); |
||
| 120 | foreach ($items as $itemData) { |
||
| 121 | $id = $itemData['iid']; |
||
| 122 | /** @var CForumThread $resource */ |
||
| 123 | $resource = $forumThreadRepo->find($id); |
||
| 124 | if ($resource->hasResourceNode()) { |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | $result = $this->fixItemProperty( |
||
| 128 | 'forum_thread', |
||
| 129 | $forumThreadRepo, |
||
| 130 | $course, |
||
| 131 | $admin, |
||
| 132 | $resource, |
||
| 133 | $course |
||
| 134 | ); |
||
| 135 | |||
| 136 | if (false === $result) { |
||
| 137 | continue; |
||
| 138 | } |
||
| 139 | |||
| 140 | $em->persist($resource); |
||
| 141 | $em->flush(); |
||
| 142 | } |
||
| 143 | |||
| 144 | $em->clear(); |
||
| 145 | } |
||
| 148 |