| Conditions | 5 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 30 |
| 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 |
||
| 23 | public function up(Schema $schema): void |
||
| 24 | { |
||
| 25 | $em = $this->getEntityManager(); |
||
| 26 | |||
| 27 | $connection = $em->getConnection(); |
||
| 28 | |||
| 29 | $thematicRepo = $em->getRepository(CThematic::class); |
||
| 30 | $courseRepo = $em->getRepository(Course::class); |
||
| 31 | |||
| 32 | $admin = $this->getAdmin(); |
||
| 33 | |||
| 34 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
| 35 | |||
| 36 | /** @var Course $course */ |
||
| 37 | foreach ($q->toIterable() as $course) { |
||
| 38 | $courseId = $course->getId(); |
||
| 39 | |||
| 40 | // c_thematic. |
||
| 41 | $sql = "SELECT * FROM c_thematic WHERE c_id = {$courseId} and active = 1 |
||
| 42 | ORDER BY iid"; |
||
| 43 | $result = $connection->executeQuery($sql); |
||
| 44 | $items = $result->fetchAllAssociative(); |
||
| 45 | foreach ($items as $itemData) { |
||
| 46 | $id = $itemData['iid']; |
||
| 47 | |||
| 48 | /** @var CThematic $resource */ |
||
| 49 | $resource = $thematicRepo->find($id); |
||
| 50 | if ($resource->hasResourceNode()) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | |||
| 54 | $course = $courseRepo->find($courseId); |
||
| 55 | |||
| 56 | $result = $this->fixItemProperty( |
||
| 57 | 'thematic', |
||
| 58 | $thematicRepo, |
||
| 59 | $course, |
||
| 60 | $admin, |
||
| 61 | $resource, |
||
| 62 | $course |
||
| 63 | ); |
||
| 64 | |||
| 65 | if (false === $result) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | $em->persist($resource); |
||
| 70 | $em->flush(); |
||
| 71 | } |
||
| 72 | |||
| 73 | $em->flush(); |
||
| 74 | $em->clear(); |
||
| 75 | |||
| 143 |