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