Conditions | 13 |
Paths | 9 |
Total Lines | 123 |
Code Lines | 77 |
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 |
||
34 | public function up(Schema $schema): void |
||
35 | { |
||
36 | /** @var ResourceRepository $portfolioRepo */ |
||
37 | $portfolioRepo = $this->container->get(PortfolioRepository::class); |
||
|
|||
38 | |||
39 | /** @var ResourceRepository $commentRepo */ |
||
40 | $commentRepo = $this->container->get(PortfolioCommentRepository::class); |
||
41 | |||
42 | /** @var UserRepository $userRepo */ |
||
43 | $userRepo = $this->container->get(UserRepository::class); |
||
44 | |||
45 | $commentRows = $this->connection |
||
46 | ->executeQuery('SELECT * FROM portfolio_comment ORDER BY id ASC') |
||
47 | ->fetchAllAssociative() |
||
48 | ; |
||
49 | |||
50 | foreach ($commentRows as $commentRow) { |
||
51 | /** @var PortfolioComment $comment */ |
||
52 | $comment = $commentRepo->find($commentRow['id']); |
||
53 | |||
54 | /** @var User $author */ |
||
55 | $author = $userRepo->find($commentRow['author_id']); |
||
56 | |||
57 | /** @var Portfolio $item */ |
||
58 | $item = $portfolioRepo->find($commentRow['item_id']); |
||
59 | |||
60 | /** @var PortfolioComment $parent */ |
||
61 | $parent = $commentRow['parent_id'] ? $commentRepo->find($commentRow['parent_id']) : null; |
||
62 | $visibility = (int) $commentRow['visibility']; |
||
63 | $creationDate = new DateTime($commentRow['date']); |
||
64 | $resourceParent = $parent ?: $item; |
||
65 | |||
66 | $comment->setParent($resourceParent); |
||
67 | |||
68 | $resourceNode = $portfolioRepo->addResourceNode( |
||
69 | $comment, |
||
70 | $author, |
||
71 | $resourceParent, |
||
72 | ); |
||
73 | |||
74 | $this->entityManager->persist($resourceNode); |
||
75 | $this->entityManager->flush(); |
||
76 | |||
77 | $resourceNode |
||
78 | ->setCreatedAt($creationDate) |
||
79 | ->setUpdatedAt($creationDate) |
||
80 | ; |
||
81 | |||
82 | $this->entityManager->flush(); |
||
83 | |||
84 | $courseLinkVisibility = match ($visibility) { |
||
85 | PortfolioComment::VISIBILITY_VISIBLE => ResourceLink::VISIBILITY_PUBLISHED, |
||
86 | default => ResourceLink::VISIBILITY_PENDING, |
||
87 | }; |
||
88 | |||
89 | $itemsProperty = $this->connection |
||
90 | ->executeQuery( |
||
91 | "SELECT * FROM c_item_property |
||
92 | WHERE tool = 'portfolio_comment' AND ref = {$comment->getId()}" |
||
93 | ) |
||
94 | ->fetchAllAssociative() |
||
95 | ; |
||
96 | |||
97 | if (empty($itemsProperty)) { |
||
98 | $itemRow = $this->connection |
||
99 | ->executeQuery("SELECT * FROM portfolio WHERE id = {$commentRow['item_id']}") |
||
100 | ->fetchAssociative() |
||
101 | ; |
||
102 | |||
103 | if ($itemRow && !empty($itemRow['c_id'])) { |
||
104 | $course = $this->findCourse($itemRow['c_id']); |
||
105 | $session = $itemRow['session_id'] ? $this->findSession($itemRow['session_id']) : null; |
||
106 | $creationDate = new DateTime($itemRow['creation_date']); |
||
107 | $updateDate = new DateTime($itemRow['update_date']); |
||
108 | |||
109 | $courseLink = $comment->addCourseLink( |
||
110 | $course, |
||
111 | $session, |
||
112 | null, |
||
113 | $courseLinkVisibility, |
||
114 | $creationDate, |
||
115 | $updateDate |
||
116 | ); |
||
117 | |||
118 | $this->entityManager->persist($courseLink); |
||
119 | } |
||
120 | } else { |
||
121 | foreach ($itemsProperty as $itemProperty) { |
||
122 | $course = $itemProperty['c_id'] ? $this->findCourse($itemProperty['c_id']) : null; |
||
123 | $session = $itemProperty['session_id'] ? $this->findSession($itemProperty['session_id']) : null; |
||
124 | $toUser = $itemProperty['to_user_id'] ? $userRepo->find($itemProperty['to_user_id']) : null; |
||
125 | $insertDate = new DateTime($itemProperty['insert_date'], new DateTimeZone('UTC')); |
||
126 | $editDate = new DateTime($itemProperty['lastedit_date'], new DateTimeZone('UTC')); |
||
127 | |||
128 | $resourceNode->setUpdatedAt($editDate); |
||
129 | |||
130 | if ($toUser) { |
||
131 | $userLink = $comment->addUserLink( |
||
132 | $toUser, |
||
133 | $course, |
||
134 | $session, |
||
135 | null, |
||
136 | $insertDate, |
||
137 | $editDate, |
||
138 | ); |
||
139 | |||
140 | $this->entityManager->persist($userLink); |
||
141 | } else { |
||
142 | $courseLink = $comment->addCourseLink( |
||
143 | $course, |
||
144 | $session, |
||
145 | null, |
||
146 | $courseLinkVisibility, |
||
147 | $insertDate, |
||
148 | $editDate |
||
149 | ); |
||
150 | |||
151 | $this->entityManager->persist($courseLink); |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | $this->entityManager->flush(); |
||
157 | } |
||
160 |
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.