| Conditions | 5 |
| Paths | 5 |
| Total Lines | 55 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 | $wikiRepo = $container->get(CWikiRepository::class); |
||
| 35 | $courseRepo = $container->get(CourseRepository::class); |
||
| 36 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 37 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 38 | $userRepo = $container->get(UserRepository::class); |
||
| 39 | /** @var Kernel $kernel */ |
||
| 40 | $kernel = $container->get('kernel'); |
||
| 41 | $rootPath = $kernel->getProjectDir(); |
||
| 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 | $courseId = $course->getId(); |
||
| 49 | $course = $courseRepo->find($courseId); |
||
| 50 | |||
| 51 | $sql = "SELECT * FROM c_wiki WHERE c_id = $courseId ORDER BY iid"; |
||
| 52 | $result = $connection->executeQuery($sql); |
||
| 53 | $items = $result->fetchAllAssociative(); |
||
| 54 | foreach ($items as $itemData) { |
||
| 55 | $id = $itemData['iid']; |
||
| 56 | /** @var CWiki $resource */ |
||
| 57 | $resource = $wikiRepo->find($id); |
||
| 58 | if ($resource->hasResourceNode()) { |
||
| 59 | continue; |
||
| 60 | } |
||
| 61 | |||
| 62 | $result = $this->fixItemProperty( |
||
| 63 | 'wiki', |
||
| 64 | $wikiRepo, |
||
| 65 | $course, |
||
| 66 | $admin, |
||
| 67 | $resource, |
||
| 68 | $course |
||
| 69 | ); |
||
| 70 | |||
| 71 | if (false === $result) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | $em->persist($resource); |
||
| 76 | $em->flush(); |
||
| 77 | } |
||
| 78 | |||
| 79 | $em->flush(); |
||
| 80 | $em->clear(); |
||
| 81 | } |
||
| 84 |