Conditions | 11 |
Paths | 14 |
Total Lines | 51 |
Code Lines | 30 |
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 |
||
22 | public function up(Schema $schema): void |
||
23 | { |
||
24 | // File generated in the Version20180928172830 migration |
||
25 | $toolLinksContent = $this->readFile('tool_links'); |
||
26 | |||
27 | if (empty($toolLinksContent)) { |
||
28 | $this->write('tool_links file not found. Exiting.'); |
||
29 | |||
30 | return; |
||
31 | } |
||
32 | |||
33 | $toolLinks = unserialize($toolLinksContent); |
||
34 | |||
35 | $container = $this->getContainer(); |
||
36 | $em = $this->getEntityManager(); |
||
37 | $lpRepo = $container->get(CLpRepository::class); |
||
38 | $lpCategoryRepo = $container->get(CLpCategoryRepository::class); |
||
39 | $shortcutRepo = $container->get(CShortcutRepository::class); |
||
40 | |||
41 | foreach ($toolLinks as $toolLink) { |
||
42 | $url = parse_url($toolLink['link']); |
||
43 | $query = []; |
||
44 | parse_str($url['query'] ?? '', $query); |
||
45 | |||
46 | $admin = $this->getAdmin(); |
||
47 | $course = $this->findCourse($toolLink['c_id']); |
||
48 | $session = $this->findSession($toolLink['session_id']); |
||
49 | $resource = null; |
||
50 | |||
51 | if (str_contains($url['path'], 'lp_controller.php') && isset($query['action'])) { |
||
52 | if (isset($query['lp_id']) && 'view' === $query['action']) { |
||
53 | $resource = $lpRepo->find($query['lp_id']); |
||
54 | } elseif (isset($query['id']) && 'view_category' === $query['action']) { |
||
55 | $resource = $lpCategoryRepo->find($query['id']); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | if ($resource) { |
||
60 | $shortcut = $shortcutRepo->getShortcutFromResource($resource); |
||
61 | |||
62 | if ($shortcut) { |
||
63 | continue; |
||
64 | } |
||
65 | |||
66 | $shortcutRepo->addShortCut($resource, $admin, $course, $session); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | $em->flush(); |
||
71 | |||
72 | $this->removeFile('tool_links'); |
||
73 | } |
||
75 |