| Conditions | 10 |
| Paths | 41 |
| Total Lines | 90 |
| Code Lines | 59 |
| 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 |
||
| 28 | public function up(Schema $schema): void |
||
| 29 | { |
||
| 30 | $courseRepo = $this->container->get(CourseRepository::class); |
||
|
|
|||
| 31 | $sessionRepo = $this->container->get(SessionRepository::class); |
||
| 32 | $groupRepo = $this->container->get(CGroupRepository::class); |
||
| 33 | $groupCategoryRepo = $this->container->get(CGroupCategoryRepository::class); |
||
| 34 | |||
| 35 | $batchSize = self::BATCH_SIZE; |
||
| 36 | |||
| 37 | // Migrating c_tool. |
||
| 38 | $q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 39 | |||
| 40 | /** @var Course $course */ |
||
| 41 | foreach ($q->toIterable() as $course) { |
||
| 42 | // Categories |
||
| 43 | $counter = 1; |
||
| 44 | $courseId = $course->getId(); |
||
| 45 | $sql = "SELECT * FROM c_group_category |
||
| 46 | WHERE c_id = {$courseId} "; |
||
| 47 | $result = $this->connection->executeQuery($sql); |
||
| 48 | $categories = $result->fetchAllAssociative(); |
||
| 49 | |||
| 50 | foreach ($categories as $categoryData) { |
||
| 51 | /** @var CGroupCategory $category */ |
||
| 52 | $category = $groupCategoryRepo->find($categoryData['iid']); |
||
| 53 | if ($category->hasResourceNode()) { |
||
| 54 | continue; |
||
| 55 | } |
||
| 56 | |||
| 57 | $course = $courseRepo->find($courseId); |
||
| 58 | $session = null; |
||
| 59 | /*if (!empty($groupData['session_id'])) { |
||
| 60 | $session = $sessionRepo->find($groupData['session_id']); |
||
| 61 | }*/ |
||
| 62 | |||
| 63 | $admin = $this->getAdmin(); |
||
| 64 | $category->setParent($course); |
||
| 65 | $groupRepo->addResourceNode($category, $admin, $course); |
||
| 66 | $newVisibility = ResourceLink::VISIBILITY_PUBLISHED; |
||
| 67 | $category->addCourseLink($course, $session, null, $newVisibility); |
||
| 68 | $this->entityManager->persist($category); |
||
| 69 | if (($counter % $batchSize) === 0) { |
||
| 70 | $this->entityManager->flush(); |
||
| 71 | $this->entityManager->clear(); |
||
| 72 | } |
||
| 73 | $counter++; |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->entityManager->flush(); |
||
| 77 | $this->entityManager->clear(); |
||
| 78 | |||
| 79 | // Groups |
||
| 80 | $counter = 1; |
||
| 81 | $courseId = $course->getId(); |
||
| 82 | $sql = "SELECT * FROM c_group_info |
||
| 83 | WHERE c_id = {$courseId} "; |
||
| 84 | $result = $this->connection->executeQuery($sql); |
||
| 85 | $groups = $result->fetchAllAssociative(); |
||
| 86 | |||
| 87 | foreach ($groups as $groupData) { |
||
| 88 | /** @var CGroup $group */ |
||
| 89 | $group = $groupRepo->find($groupData['iid']); |
||
| 90 | if ($group->hasResourceNode()) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | |||
| 94 | $course = $courseRepo->find($courseId); |
||
| 95 | $session = null; |
||
| 96 | if (!empty($groupData['session_id'])) { |
||
| 97 | $session = $sessionRepo->find($groupData['session_id']); |
||
| 98 | } |
||
| 99 | |||
| 100 | $admin = $this->getAdmin(); |
||
| 101 | $group->setParent($course); |
||
| 102 | $groupRepo->addResourceNode($group, $admin, $course); |
||
| 103 | $newVisibility = ResourceLink::VISIBILITY_PENDING; |
||
| 104 | if (1 === $group->getStatus()) { |
||
| 105 | $newVisibility = ResourceLink::VISIBILITY_PUBLISHED; |
||
| 106 | } |
||
| 107 | $group->addCourseLink($course, $session, null, $newVisibility); |
||
| 108 | $this->entityManager->persist($group); |
||
| 109 | if (($counter % $batchSize) === 0) { |
||
| 110 | $this->entityManager->flush(); |
||
| 111 | $this->entityManager->clear(); |
||
| 112 | } |
||
| 113 | $counter++; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | $this->entityManager->flush(); |
||
| 117 | $this->entityManager->clear(); |
||
| 118 | } |
||
| 120 |
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.