Conditions | 8 |
Paths | 21 |
Total Lines | 54 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 | $this->entityManager->beginTransaction(); |
||
|
|||
27 | |||
28 | try { |
||
29 | if (!$this->tableExists('extra_field') || !$this->tableExists('extra_field_values')) { |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | /** @var AccessUrlRepository $accessUrlRepo */ |
||
34 | $accessUrlRepo = $this->container->get(AccessUrlRepository::class); |
||
35 | $accessUrlId = $accessUrlRepo->getFirstId(); |
||
36 | |||
37 | if ($accessUrlId === 0) { |
||
38 | throw new Exception('No AccessUrl found for migration'); |
||
39 | } |
||
40 | |||
41 | /** @var AccessUrl|null $accessUrl */ |
||
42 | $accessUrl = $this->entityManager->find(AccessUrl::class, $accessUrlId); |
||
43 | if (!$accessUrl) { |
||
44 | throw new Exception('AccessUrl entity not found for ID: ' . $accessUrlId); |
||
45 | } |
||
46 | |||
47 | $courseRepo = $this->entityManager->getRepository(Course::class); |
||
48 | |||
49 | $courseIds = $this->connection->fetchFirstColumn(' |
||
50 | SELECT fv.item_id |
||
51 | FROM extra_field_values fv |
||
52 | INNER JOIN extra_field f ON f.id = fv.field_id |
||
53 | WHERE f.item_type = 2 |
||
54 | AND f.variable = "show_in_catalogue" |
||
55 | AND fv.field_value = 1 |
||
56 | '); |
||
57 | |||
58 | foreach ($courseIds as $courseId) { |
||
59 | $course = $courseRepo->find($courseId); |
||
60 | |||
61 | if (!$course) { |
||
62 | continue; |
||
63 | } |
||
64 | |||
65 | $rel = new CatalogueCourseRelAccessUrlRelUsergroup(); |
||
66 | $rel->setAccessUrl($accessUrl); |
||
67 | $rel->setCourse($course); |
||
68 | $rel->setUsergroup(null); |
||
69 | |||
70 | $this->entityManager->persist($rel); |
||
71 | } |
||
72 | |||
73 | $this->entityManager->flush(); |
||
74 | $this->entityManager->commit(); |
||
75 | } catch (Exception $e) { |
||
76 | $this->entityManager->rollBack(); |
||
77 | error_log('Migration failed: ' . $e->getMessage()); |
||
78 | } |
||
96 |
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.