| Conditions | 5 |
| Paths | 5 |
| Total Lines | 55 |
| Code Lines | 37 |
| 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 | $container = $this->getContainer(); |
||
| 31 | $doctrine = $container->get('doctrine'); |
||
| 32 | $em = $doctrine->getManager(); |
||
| 33 | /** @var Connection $connection */ |
||
| 34 | $connection = $em->getConnection(); |
||
| 35 | |||
| 36 | $surveyRepo = $container->get(CSurveyRepository::class); |
||
| 37 | $courseRepo = $container->get(CourseRepository::class); |
||
| 38 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 39 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 40 | $userRepo = $container->get(UserRepository::class); |
||
| 41 | /** @var Kernel $kernel */ |
||
| 42 | $kernel = $container->get('kernel'); |
||
| 43 | $rootPath = $kernel->getProjectDir(); |
||
| 44 | |||
| 45 | $admin = $this->getAdmin(); |
||
| 46 | |||
| 47 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 48 | /** @var Course $course */ |
||
| 49 | foreach ($q->toIterable() as $course) { |
||
| 50 | $courseId = $course->getId(); |
||
| 51 | $course = $courseRepo->find($courseId); |
||
| 52 | |||
| 53 | $sql = "SELECT * FROM c_survey WHERE c_id = {$courseId} ORDER BY iid"; |
||
| 54 | $result = $connection->executeQuery($sql); |
||
| 55 | $items = $result->fetchAllAssociative(); |
||
| 56 | foreach ($items as $itemData) { |
||
| 57 | $id = $itemData['iid']; |
||
| 58 | /** @var CSurvey $resource */ |
||
| 59 | $resource = $surveyRepo->find($id); |
||
| 60 | if ($resource->hasResourceNode()) { |
||
| 61 | continue; |
||
| 62 | } |
||
| 63 | |||
| 64 | $result = $this->fixItemProperty( |
||
| 65 | 'survey', |
||
| 66 | $surveyRepo, |
||
| 67 | $course, |
||
| 68 | $admin, |
||
| 69 | $resource, |
||
| 70 | $course |
||
| 71 | ); |
||
| 72 | |||
| 73 | if (false === $result) { |
||
| 74 | continue; |
||
| 75 | } |
||
| 76 | |||
| 77 | $em->persist($resource); |
||
| 78 | $em->flush(); |
||
| 79 | } |
||
| 80 | |||
| 81 | $em->flush(); |
||
| 82 | $em->clear(); |
||
| 83 | } |
||
| 86 |