| Conditions | 5 |
| Paths | 5 |
| Total Lines | 60 |
| Code Lines | 39 |
| 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 |
||
| 30 | public function up(Schema $schema): void |
||
| 31 | { |
||
| 32 | $container = $this->getContainer(); |
||
| 33 | $doctrine = $container->get('doctrine'); |
||
| 34 | $em = $doctrine->getManager(); |
||
| 35 | /** @var Connection $connection */ |
||
| 36 | $connection = $em->getConnection(); |
||
| 37 | |||
| 38 | $thematicRepo = $container->get(CThematicRepository::class); |
||
| 39 | $thematicAdvanceRepo = $container->get(CThematicAdvanceRepository::class); |
||
| 40 | $thematicPlanRepo = $container->get(CThematicPlanRepository::class); |
||
| 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 | $admin = $this->getAdmin(); |
||
| 50 | |||
| 51 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 52 | /** @var Course $course */ |
||
| 53 | foreach ($q->toIterable() as $course) { |
||
| 54 | $courseId = $course->getId(); |
||
| 55 | |||
| 56 | // c_thematic. |
||
| 57 | $sql = "SELECT * FROM c_thematic 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 CThematic $resource */ |
||
| 64 | $resource = $thematicRepo->find($id); |
||
| 65 | if ($resource->hasResourceNode()) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | $course = $courseRepo->find($courseId); |
||
| 70 | |||
| 71 | $result = $this->fixItemProperty( |
||
| 72 | 'thematic', |
||
| 73 | $thematicRepo, |
||
| 74 | $course, |
||
| 75 | $admin, |
||
| 76 | $resource, |
||
| 77 | $course |
||
| 78 | ); |
||
| 79 | |||
| 80 | if (false === $result) { |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | $em->persist($resource); |
||
| 85 | $em->flush(); |
||
| 86 | } |
||
| 87 | |||
| 88 | $em->flush(); |
||
| 89 | $em->clear(); |
||
| 90 | |||
| 158 |