| Conditions | 8 |
| Paths | 13 |
| Total Lines | 84 |
| Code Lines | 54 |
| 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 |
||
| 25 | public function up(Schema $schema): void |
||
| 26 | { |
||
| 27 | $container = $this->getContainer(); |
||
| 28 | $em = $this->getEntityManager(); |
||
| 29 | $connection = $em->getConnection(); |
||
| 30 | |||
| 31 | $batchSize = self::BATCH_SIZE; |
||
| 32 | |||
| 33 | $introRepo = $container->get(CToolIntroRepository::class); |
||
| 34 | $cToolRepo = $container->get(CToolRepository::class); |
||
| 35 | $toolRepo = $container->get(ToolRepository::class); |
||
| 36 | |||
| 37 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 38 | $courseRepo = $container->get(CourseRepository::class); |
||
| 39 | |||
| 40 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 41 | |||
| 42 | /** @var Course $course */ |
||
| 43 | foreach ($q->toIterable() as $course) { |
||
| 44 | $courseId = $course->getId(); |
||
| 45 | $sql = "SELECT * FROM c_tool_intro WHERE c_id = {$courseId} |
||
| 46 | ORDER BY iid"; |
||
| 47 | $result = $connection->executeQuery($sql); |
||
| 48 | $items = $result->fetchAllAssociative(); |
||
| 49 | foreach ($items as $itemData) { |
||
| 50 | $id = $itemData['iid']; |
||
| 51 | $sessionId = (int) $itemData['session_id']; |
||
| 52 | $toolName = $itemData['id']; |
||
| 53 | |||
| 54 | /** @var CToolIntro $intro */ |
||
| 55 | $intro = $introRepo->find($id); |
||
| 56 | |||
| 57 | if ($intro->hasResourceNode()) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | |||
| 61 | $session = null; |
||
| 62 | if (!empty($sessionId)) { |
||
| 63 | $session = $sessionRepo->find($sessionId); |
||
| 64 | } |
||
| 65 | |||
| 66 | $admin = $this->getAdmin(); |
||
| 67 | |||
| 68 | $cTool = null; |
||
| 69 | if ('course_homepage' === $toolName) { |
||
| 70 | $tool = $toolRepo->findOneBy(['name' => $toolName]); |
||
| 71 | |||
| 72 | if (null === $tool) { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | |||
| 76 | $course = $courseRepo->find($courseId); |
||
| 77 | |||
| 78 | $cTool = (new CTool()) |
||
| 79 | ->setName('course_homepage') |
||
| 80 | ->setCourse($course) |
||
| 81 | ->setSession($session) |
||
| 82 | ->setTool($tool) |
||
| 83 | ->setCreator($admin) |
||
| 84 | ->setParent($course) |
||
| 85 | ->addCourseLink($course, $session) |
||
| 86 | ; |
||
| 87 | $em->persist($cTool); |
||
| 88 | } else { |
||
| 89 | $cTool = $cToolRepo->findCourseResourceByTitle($toolName, $course->getResourceNode(), $course, $session); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (null === $cTool) { |
||
| 93 | continue; |
||
| 94 | } |
||
| 95 | |||
| 96 | $intro |
||
| 97 | ->setParent($course) |
||
| 98 | ->setCourseTool($cTool) |
||
| 99 | ; |
||
| 100 | $introRepo->addResourceNode($intro, $admin, $course); |
||
| 101 | $intro->addCourseLink($course, $session); |
||
| 102 | |||
| 103 | $em->persist($intro); |
||
| 104 | $em->flush(); |
||
| 105 | } |
||
| 106 | |||
| 107 | $em->flush(); |
||
| 108 | $em->clear(); |
||
| 109 | } |
||
| 116 |