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