| Conditions | 10 |
| Paths | 33 |
| Total Lines | 86 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 | $linkRepo = $container->get(CLinkRepository::class); |
||
| 37 | $linkCategoryRepo = $container->get(CLinkCategoryRepository::class); |
||
| 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 | $admin = $this->getAdmin(); |
||
| 44 | |||
| 45 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 46 | /** @var Course $course */ |
||
| 47 | foreach ($q->toIterable() as $course) { |
||
| 48 | $counter = 1; |
||
| 49 | $courseId = $course->getId(); |
||
| 50 | $course = $courseRepo->find($courseId); |
||
| 51 | |||
| 52 | $sql = "SELECT * FROM c_link_category WHERE c_id = $courseId |
||
| 53 | ORDER BY iid"; |
||
| 54 | $result = $connection->executeQuery($sql); |
||
| 55 | $items = $result->fetchAllAssociative(); |
||
| 56 | foreach ($items as $itemData) { |
||
| 57 | $id = $itemData['iid']; |
||
| 58 | /** @var CLinkCategory $event */ |
||
| 59 | $resource = $linkCategoryRepo->find($id); |
||
| 60 | if ($resource->hasResourceNode()) { |
||
| 61 | continue; |
||
| 62 | } |
||
| 63 | $result = $this->fixItemProperty( |
||
| 64 | 'link_category', |
||
| 65 | $linkCategoryRepo, |
||
| 66 | $course, |
||
| 67 | $admin, |
||
| 68 | $resource, |
||
| 69 | $course |
||
| 70 | ); |
||
| 71 | |||
| 72 | if (false === $result) { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | $em->persist($resource); |
||
| 76 | $em->flush(); |
||
| 77 | } |
||
| 78 | |||
| 79 | $sql = "SELECT * FROM c_link WHERE c_id = $courseId |
||
| 80 | ORDER BY iid"; |
||
| 81 | $result = $connection->executeQuery($sql); |
||
| 82 | $items = $result->fetchAllAssociative(); |
||
| 83 | foreach ($items as $itemData) { |
||
| 84 | $id = $itemData['iid']; |
||
| 85 | $categoryId = $itemData['category_id']; |
||
| 86 | /** @var CLink $event */ |
||
| 87 | $resource = $linkRepo->find($id); |
||
| 88 | if ($resource->hasResourceNode()) { |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | $parent = $course; |
||
| 92 | |||
| 93 | if (!empty($categoryId)) { |
||
| 94 | $category = $linkCategoryRepo->find($categoryId); |
||
| 95 | if (null !== $category) { |
||
| 96 | $parent = $category; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | $result = $this->fixItemProperty( |
||
| 101 | 'link', |
||
| 102 | $linkRepo, |
||
| 103 | $course, |
||
| 104 | $admin, |
||
| 105 | $resource, |
||
| 106 | $parent |
||
| 107 | ); |
||
| 108 | |||
| 109 | if (false === $result) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | $em->persist($resource); |
||
| 113 | $em->flush(); |
||
| 114 | } |
||
| 118 |