| Conditions | 8 |
| Paths | 21 |
| Total Lines | 94 |
| Code Lines | 63 |
| 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 | foreach ($portfolioRows as $portfolioRow) { |
||
| 41 | $portfolioId = $portfolioRow['id']; |
||
| 42 | $creatorId = $portfolioRow['user_id']; |
||
| 43 | $courseId = $portfolioRow['c_id']; |
||
| 44 | $sessionId = $portfolioRow['session_id']; |
||
| 45 | $creationDate = new DateTime($portfolioRow['creation_date']); |
||
| 46 | $updateDate = new DateTime($portfolioRow['update_date']); |
||
| 47 | |||
| 48 | /** @var Portfolio $portfolio */ |
||
| 49 | $portfolio = $portfolioRepo->find($portfolioId); |
||
| 50 | $creator = $userRepo->find($creatorId); |
||
| 51 | $course = $courseId ? $this->findCourse($courseId) : null; |
||
| 52 | $session = $sessionId ? $this->findSession($sessionId) : null; |
||
| 53 | |||
| 54 | $portfolio->setParent($creator); |
||
| 55 | |||
| 56 | $resourceNode = $portfolioRepo->addResourceNode( |
||
| 57 | $portfolio, |
||
| 58 | $creator, |
||
| 59 | $creator |
||
| 60 | ); |
||
| 61 | |||
| 62 | $this->entityManager->persist($resourceNode); |
||
| 63 | $this->entityManager->flush(); |
||
| 64 | |||
| 65 | $resourceNode |
||
| 66 | ->setCreatedAt($creationDate) |
||
| 67 | ->setUpdatedAt($updateDate); |
||
| 68 | |||
| 69 | $this->entityManager->flush(); |
||
| 70 | |||
| 71 | if ($course) { |
||
| 72 | $resourceVisibility = match ($portfolio->getVisibility()) { |
||
| 73 | Portfolio::VISIBILITY_HIDDEN => ResourceLink::VISIBILITY_DRAFT, |
||
| 74 | Portfolio::VISIBILITY_VISIBLE => ResourceLink::VISIBILITY_PUBLISHED, |
||
| 75 | default => ResourceLink::VISIBILITY_PENDING, |
||
| 76 | }; |
||
| 77 | |||
| 78 | $courseLink = $portfolio->addCourseLink( |
||
| 79 | $course, |
||
| 80 | $session, |
||
| 81 | null, |
||
| 82 | $resourceVisibility, |
||
| 83 | $creationDate, |
||
| 84 | $updateDate |
||
| 85 | ); |
||
| 86 | |||
| 87 | $this->entityManager->persist($courseLink); |
||
| 88 | $this->entityManager->flush(); |
||
| 89 | |||
| 90 | |||
| 91 | $itemsProperty = $this->connection |
||
| 92 | ->executeQuery( |
||
| 93 | "SELECT * FROM c_item_property |
||
| 94 | WHERE tool = 'portfolio' AND ref = $portfolioId" |
||
| 95 | ) |
||
| 96 | ->fetchAllAssociative(); |
||
| 97 | |||
| 98 | foreach ($itemsProperty as $itemProperty) { |
||
| 99 | if (empty($itemProperty['to_user_id'])) { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** @var User|null $toUser */ |
||
| 104 | $toUser = $userRepo->find($itemProperty['to_user_id']); |
||
| 105 | |||
| 106 | if (!$toUser) { |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | $insertDate = new DateTime($itemProperty['insert_date']); |
||
| 111 | $lastEditDate = new DateTime($itemProperty['lastedit_date']); |
||
| 112 | |||
| 113 | $userLink = $portfolio->addUserLink( |
||
| 114 | $toUser, |
||
| 115 | $course, |
||
| 116 | $session, |
||
| 117 | null, |
||
| 118 | $insertDate, |
||
| 119 | $lastEditDate |
||
| 120 | ); |
||
| 121 | |||
| 122 | $this->entityManager->persist($userLink); |
||
| 123 | $this->entityManager->flush(); |
||
| 124 | } |
||
| 129 |
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.