Conditions | 7 |
Paths | 18 |
Total Lines | 87 |
Code Lines | 57 |
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 | /** @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 id, author_id, item_id, visibility, 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 | $visibility = (int) $commentRow['visibility']; |
||
55 | $creationDate = new DateTime($commentRow['date']); |
||
56 | |||
57 | $comment->setParent($item); |
||
58 | |||
59 | $resourceNode = $portfolioRepo->addResourceNode( |
||
60 | $comment, |
||
61 | $author, |
||
62 | $item |
||
63 | ); |
||
64 | |||
65 | $this->entityManager->persist($resourceNode); |
||
66 | $this->entityManager->flush(); |
||
67 | |||
68 | $resourceNode |
||
69 | ->setCreatedAt($creationDate) |
||
70 | ->setUpdatedAt($creationDate); |
||
71 | |||
72 | $this->entityManager->flush(); |
||
73 | |||
74 | $courseLinkVisibility = match ($visibility) { |
||
75 | PortfolioComment::VISIBILITY_VISIBLE => ResourceLink::VISIBILITY_PUBLISHED, |
||
76 | default => ResourceLink::VISIBILITY_PENDING, |
||
77 | }; |
||
78 | |||
79 | $itemsProperty = $this->connection |
||
80 | ->executeQuery( |
||
81 | "SELECT * FROM c_item_property |
||
82 | WHERE tool = 'portfolio_comment' AND ref = {$comment->getId()}" |
||
83 | ) |
||
84 | ->fetchAllAssociative(); |
||
85 | |||
86 | foreach ($itemsProperty as $itemProperty) { |
||
87 | $course = $itemProperty['c_id'] ? $this->findCourse($itemProperty['c_id']) : null; |
||
88 | $session = $itemProperty['session_id'] ? $this->findSession($itemProperty['session_id']) : null; |
||
89 | $toUser = $itemProperty['to_user_id'] ? $userRepo->find($itemProperty['to_user_id']) : null; |
||
90 | $insertDate = new DateTime($itemProperty['insert_date'], new DateTimeZone('UTC')); |
||
91 | $editDate = new DateTime($itemProperty['lastedit_date'], new DateTimeZone('UTC')); |
||
92 | |||
93 | $resourceNode->setUpdatedAt($editDate); |
||
94 | |||
95 | if ($toUser) { |
||
96 | $userLink = $comment->addUserLink( |
||
97 | $toUser, |
||
98 | $course, |
||
99 | $session, |
||
100 | null, |
||
101 | $insertDate, |
||
102 | $editDate, |
||
103 | ); |
||
104 | |||
105 | $this->entityManager->persist($userLink); |
||
106 | } else { |
||
107 | $courseLink = $comment->addCourseLink( |
||
108 | $course, |
||
109 | $session, |
||
110 | null, |
||
111 | $courseLinkVisibility, |
||
112 | $insertDate, |
||
113 | $editDate |
||
114 | ); |
||
115 | |||
116 | $this->entityManager->persist($courseLink); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | $this->entityManager->flush(); |
||
121 | } |
||
124 |
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.