| Conditions | 11 |
| Paths | 9 |
| Total Lines | 102 |
| Code Lines | 69 |
| 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 |
||
| 30 | public function up(Schema $schema): void |
||
| 31 | { |
||
| 32 | /** @var ResourceRepository $portfolioRepo */ |
||
| 33 | $portfolioRepo = $this->container->get(PortfolioRepository::class); |
||
|
|
|||
| 34 | $userRepo = $this->container->get(UserRepository::class); |
||
| 35 | |||
| 36 | $portfolioRows = $this->connection |
||
| 37 | ->executeQuery('SELECT * FROM portfolio ORDER BY id ASC') |
||
| 38 | ->fetchAllAssociative() |
||
| 39 | ; |
||
| 40 | |||
| 41 | foreach ($portfolioRows as $portfolioRow) { |
||
| 42 | $portfolioId = $portfolioRow['id']; |
||
| 43 | $creationDate = new DateTime($portfolioRow['creation_date']); |
||
| 44 | $updateDate = new DateTime($portfolioRow['update_date']); |
||
| 45 | |||
| 46 | /** @var Portfolio $portfolio */ |
||
| 47 | $portfolio = $portfolioRepo->find($portfolioId); |
||
| 48 | $creator = $userRepo->find($portfolioRow['user_id']); |
||
| 49 | $course = $portfolioRow['c_id'] ? $this->findCourse($portfolioRow['c_id']) : null; |
||
| 50 | $session = $portfolioRow['session_id'] ? $this->findSession($portfolioRow['session_id']) : null; |
||
| 51 | |||
| 52 | $portfolio->setParent($creator); |
||
| 53 | |||
| 54 | $resourceNode = $portfolioRepo->addResourceNode( |
||
| 55 | $portfolio, |
||
| 56 | $creator, |
||
| 57 | $creator |
||
| 58 | ); |
||
| 59 | |||
| 60 | $this->entityManager->persist($resourceNode); |
||
| 61 | $this->entityManager->flush(); |
||
| 62 | |||
| 63 | $resourceNode |
||
| 64 | ->setCreatedAt($creationDate) |
||
| 65 | ->setUpdatedAt($updateDate) |
||
| 66 | ; |
||
| 67 | |||
| 68 | $this->entityManager->flush(); |
||
| 69 | |||
| 70 | $resourceVisibility = match ($portfolio->getVisibility()) { |
||
| 71 | Portfolio::VISIBILITY_HIDDEN => ResourceLink::VISIBILITY_DRAFT, |
||
| 72 | Portfolio::VISIBILITY_VISIBLE => ResourceLink::VISIBILITY_PUBLISHED, |
||
| 73 | default => ResourceLink::VISIBILITY_PENDING, |
||
| 74 | }; |
||
| 75 | |||
| 76 | $itemsProperty = $this->connection |
||
| 77 | ->executeQuery( |
||
| 78 | "SELECT * FROM c_item_property |
||
| 79 | WHERE tool = 'portfolio' AND ref = $portfolioId" |
||
| 80 | ) |
||
| 81 | ->fetchAllAssociative() |
||
| 82 | ; |
||
| 83 | |||
| 84 | if (empty($itemsProperty) && $course) { |
||
| 85 | $courseLink = $portfolio->addCourseLink( |
||
| 86 | $course, |
||
| 87 | $session, |
||
| 88 | null, |
||
| 89 | $resourceVisibility, |
||
| 90 | $creationDate, |
||
| 91 | $updateDate |
||
| 92 | ); |
||
| 93 | |||
| 94 | $this->entityManager->persist($courseLink); |
||
| 95 | } else { |
||
| 96 | foreach ($itemsProperty as $itemProperty) { |
||
| 97 | $course = $itemProperty['c_id'] ? $this->findCourse($itemProperty['c_id']) : null; |
||
| 98 | $session = $itemProperty['session_id'] ? $this->findSession($itemProperty['session_id']) : null; |
||
| 99 | $toUser = $itemProperty['to_user_id'] ? $userRepo->find($itemProperty['to_user_id']) : null; |
||
| 100 | $insertDate = new DateTime($itemProperty['insert_date'], new DateTimeZone('UTC')); |
||
| 101 | $editDate = new DateTime($itemProperty['lastedit_date'], new DateTimeZone('UTC')); |
||
| 102 | |||
| 103 | $resourceNode->setUpdatedAt($editDate); |
||
| 104 | |||
| 105 | if ($toUser) { |
||
| 106 | $userLink = $portfolio->addUserLink( |
||
| 107 | $toUser, |
||
| 108 | $course, |
||
| 109 | $session, |
||
| 110 | null, |
||
| 111 | $insertDate, |
||
| 112 | $editDate |
||
| 113 | ); |
||
| 114 | |||
| 115 | $this->entityManager->persist($userLink); |
||
| 116 | } else { |
||
| 117 | $courseLink = $portfolio->addCourseLink( |
||
| 118 | $course, |
||
| 119 | $session, |
||
| 120 | null, |
||
| 121 | $resourceVisibility, |
||
| 122 | $creationDate, |
||
| 123 | $updateDate |
||
| 124 | ); |
||
| 125 | |||
| 126 | $this->entityManager->persist($courseLink); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->entityManager->flush(); |
||
| 132 | } |
||
| 135 |
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.