Conditions | 11 |
Paths | 14 |
Total Lines | 49 |
Code Lines | 28 |
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 | $lpRepo = $this->container->get(CLpRepository::class); |
||
|
|||
36 | $lpCategoryRepo = $this->container->get(CLpCategoryRepository::class); |
||
37 | $shortcutRepo = $this->container->get(CShortcutRepository::class); |
||
38 | |||
39 | foreach ($toolLinks as $toolLink) { |
||
40 | $url = parse_url($toolLink['link']); |
||
41 | $query = []; |
||
42 | parse_str($url['query'] ?? '', $query); |
||
43 | |||
44 | $admin = $this->getAdmin(); |
||
45 | $course = $this->findCourse($toolLink['c_id']); |
||
46 | $session = $this->findSession($toolLink['session_id']); |
||
47 | $resource = null; |
||
48 | |||
49 | if (str_contains($url['path'], 'lp_controller.php') && isset($query['action'])) { |
||
50 | if (isset($query['lp_id']) && 'view' === $query['action']) { |
||
51 | $resource = $lpRepo->find($query['lp_id']); |
||
52 | } elseif (isset($query['id']) && 'view_category' === $query['action']) { |
||
53 | $resource = $lpCategoryRepo->find($query['id']); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | if ($resource) { |
||
58 | $shortcut = $shortcutRepo->getShortcutFromResource($resource); |
||
59 | |||
60 | if ($shortcut) { |
||
61 | continue; |
||
62 | } |
||
63 | |||
64 | $shortcutRepo->addShortCut($resource, $admin, $course, $session); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $this->entityManager->flush(); |
||
69 | |||
70 | $this->removeFile('tool_links'); |
||
71 | } |
||
73 |
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.