| Conditions | 6 |
| Paths | 10 |
| Total Lines | 71 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 24 | public function up(Schema $schema): void |
||
| 25 | { |
||
| 26 | $attendanceRepo = $this->container->get(CAttendanceRepository::class); |
||
|
|
|||
| 27 | // $attendanceRepo = $container->get(CAttendanceCalendar::class); |
||
| 28 | $courseRepo = $this->container->get(CourseRepository::class); |
||
| 29 | |||
| 30 | $admin = $this->getAdmin(); |
||
| 31 | |||
| 32 | $q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 33 | |||
| 34 | // The title of the attendance table is used to create the slug in the resource_node tbale. |
||
| 35 | // Before creating a new registry in resource_node, Doctrine is looking for all the registries that start with the same name |
||
| 36 | // It then find the last one depending on the name and create new one with the "title-number" |
||
| 37 | // where title is the title of the attendance and the number is the max number all ready existing + 1 |
||
| 38 | // Since in Chamilo 1.11.x the name of the first attendance is created automatically we have a lot of attendance with the same name |
||
| 39 | // This make the migration to take a really long time if we have many attendance because this process is taking more and more time |
||
| 40 | // when creating more registry with the same name. |
||
| 41 | // So to avoid this process taking so much time : |
||
| 42 | // * Save temporarly the title and the id of all the attendance in a PHP Array |
||
| 43 | // * we modify the title of the attendance to make it unique during the migration by adding the iid at the end |
||
| 44 | // * We then process the migration |
||
| 45 | // * At the end we restore the title without the iid and also the resource_node.title |
||
| 46 | |||
| 47 | $sql = "SELECT iid, title FROM c_attendance"; |
||
| 48 | $result = $this->connection->executeQuery($sql); |
||
| 49 | $attendancesBackup = $result->fetchAllAssociative(); |
||
| 50 | $sqlUpdateTitle = "UPDATE c_attendance SET title = CONCAT(title, '-', iid)"; |
||
| 51 | $resultUpdate = $this->connection->executeQuery($sqlUpdateTitle); |
||
| 52 | |||
| 53 | /** @var Course $course */ |
||
| 54 | foreach ($q->toIterable() as $course) { |
||
| 55 | $courseId = $course->getId(); |
||
| 56 | $course = $courseRepo->find($courseId); |
||
| 57 | |||
| 58 | // c_thematic. |
||
| 59 | $sql = "SELECT * FROM c_attendance WHERE c_id = {$courseId} |
||
| 60 | ORDER BY iid"; |
||
| 61 | $result = $this->connection->executeQuery($sql); |
||
| 62 | $items = $result->fetchAllAssociative(); |
||
| 63 | foreach ($items as $itemData) { |
||
| 64 | $id = $itemData['iid']; |
||
| 65 | |||
| 66 | /** @var CAttendance $resource */ |
||
| 67 | $resource = $attendanceRepo->find($id); |
||
| 68 | if ($resource->hasResourceNode()) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | |||
| 72 | $result = $this->fixItemProperty( |
||
| 73 | 'attendance', |
||
| 74 | $attendanceRepo, |
||
| 75 | $course, |
||
| 76 | $admin, |
||
| 77 | $resource, |
||
| 78 | $course |
||
| 79 | ); |
||
| 80 | |||
| 81 | if (false === $result) { |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | $this->entityManager->persist($resource); |
||
| 86 | $this->entityManager->flush(); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | // Restoring attendance title and resource_node title |
||
| 90 | foreach ($attendancesBackup as $attendance) { |
||
| 91 | $sqlRestoreAttendance = "UPDATE c_attendance SET title = '{$attendance['title']}' where iid = {$attendance['iid']}"; |
||
| 92 | $resultUpdate = $this->connection->executeQuery($sqlRestoreAttendance); |
||
| 93 | $sqlUpdateResourceNode = "UPDATE resource_node SET title = '{$attendance['title']}' where id in (SELECT resource_node_id FROM c_attendance where iid = {$attendance['iid']})"; |
||
| 94 | $resultUpdate = $this->connection->executeQuery($sqlUpdateResourceNode); |
||
| 95 | } |
||
| 98 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.