| Conditions | 19 |
| Paths | 1172 |
| Total Lines | 120 |
| Code Lines | 83 |
| 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 |
||
| 26 | public function up(Schema $schema): void |
||
| 27 | { |
||
| 28 | $container = $this->getContainer(); |
||
| 29 | $doctrine = $container->get('doctrine'); |
||
| 30 | $em = $doctrine->getManager(); |
||
| 31 | /** @var Connection $connection */ |
||
| 32 | $connection = $em->getConnection(); |
||
| 33 | |||
| 34 | $documentRepo = $container->get(CDocumentRepository::class); |
||
| 35 | $courseRepo = $container->get(CourseRepository::class); |
||
| 36 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 37 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 38 | |||
| 39 | $userRepo = $container->get(UserRepository::class); |
||
| 40 | |||
| 41 | $userList = []; |
||
| 42 | $groupList = []; |
||
| 43 | $sessionList = []; |
||
| 44 | |||
| 45 | //$urlRepo = $container->get(AccessUrlRepository::class); |
||
| 46 | $urlRepo = $em->getRepository(AccessUrl::class); |
||
| 47 | $admin = $this->getAdmin(); |
||
| 48 | |||
| 49 | $urls = $urlRepo->findAll(); |
||
| 50 | /** @var AccessUrl $url */ |
||
| 51 | foreach ($urls as $url) { |
||
| 52 | $accessUrlRelCourses = $url->getCourses(); |
||
| 53 | /** @var AccessUrlRelCourse $accessUrlRelCourse */ |
||
| 54 | foreach ($accessUrlRelCourses as $accessUrlRelCourse) { |
||
| 55 | $course = $accessUrlRelCourse->getCourse(); |
||
| 56 | if ($course->hasResourceNode()) { |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | $courseRepo->addResourceNode($course, $admin, $url); |
||
| 60 | $em->persist($course); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $em->flush(); |
||
| 64 | |||
| 65 | $admin = $this->getAdmin(); |
||
| 66 | /** @var AccessUrl $url */ |
||
| 67 | foreach ($urls as $url) { |
||
| 68 | $accessUrlRelCourses = $url->getCourses(); |
||
| 69 | /** @var AccessUrlRelCourse $accessUrlRelCourse */ |
||
| 70 | foreach ($accessUrlRelCourses as $accessUrlRelCourse) { |
||
| 71 | $course = $accessUrlRelCourse->getCourse(); |
||
| 72 | $courseId = $course->getId(); |
||
| 73 | |||
| 74 | $sql = "SELECT * FROM c_document WHERE c_id = $courseId"; |
||
| 75 | $result = $connection->executeQuery($sql); |
||
| 76 | $documents = $result->fetchAllAssociative(); |
||
| 77 | foreach ($documents as $document) { |
||
| 78 | $documentId = $document['iid']; |
||
| 79 | /** @var CDocument $document */ |
||
| 80 | $document = $documentRepo->find($courseId); |
||
| 81 | if ($document->hasResourceNode()) { |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | $document->setParent($course); |
||
| 85 | $sql = "SELECT * FROM c_item_property |
||
| 86 | WHERE tool = 'document' AND c_id = $courseId AND ref = $documentId"; |
||
| 87 | $result = $connection->executeQuery($sql); |
||
| 88 | $items = $result->fetchAllAssociative(); |
||
| 89 | |||
| 90 | $resourceNode = null; |
||
| 91 | foreach ($items as $item) { |
||
| 92 | $sessionId = $item['session_id']; |
||
| 93 | $visibility = $item['visibility']; |
||
| 94 | $userId = $item['insert_user_id']; |
||
| 95 | $groupId = $item['to_group_id']; |
||
| 96 | |||
| 97 | $newVisibility = ResourceLink::VISIBILITY_PENDING; |
||
| 98 | switch ($visibility) { |
||
| 99 | case 0: |
||
| 100 | $newVisibility = ResourceLink::VISIBILITY_PENDING; |
||
| 101 | break; |
||
| 102 | case 1: |
||
| 103 | $newVisibility = ResourceLink::VISIBILITY_PUBLISHED; |
||
| 104 | break; |
||
| 105 | case 2: |
||
| 106 | $newVisibility = ResourceLink::VISIBILITY_DELETED; |
||
| 107 | break; |
||
| 108 | } |
||
| 109 | |||
| 110 | if (isset($userList[$userId])) { |
||
| 111 | $user = $userList[$userId]; |
||
| 112 | } else { |
||
| 113 | $user = $userList[$userId] = $userRepo->find($userId); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (null === $user) { |
||
| 117 | $user = $admin; |
||
| 118 | } |
||
| 119 | |||
| 120 | $session = null; |
||
| 121 | if (!empty($sessionId)) { |
||
| 122 | if (isset($sessionList[$sessionId])) { |
||
| 123 | $session = $sessionList[$sessionId]; |
||
| 124 | } else { |
||
| 125 | $session = $sessionList[$sessionId] = $sessionRepo->find($sessionId); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | $group = null; |
||
| 130 | if (!empty($groupId)) { |
||
| 131 | if (isset($groupList[$groupId])) { |
||
| 132 | $group = $groupList[$groupId]; |
||
| 133 | } else { |
||
| 134 | $group = $groupList[$groupId] = $groupRepo->find($groupId); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | if (null === $resourceNode) { |
||
| 139 | $documentRepo->addResourceNode($document, $user, $course); |
||
| 140 | } |
||
| 141 | $document->addCourseLink($course, $session, $group, $newVisibility); |
||
| 142 | } |
||
| 143 | $em->persist($document); |
||
| 144 | } |
||
| 145 | $em->flush(); |
||
| 146 | } |
||
| 150 |