| Conditions | 18 |
| Paths | 63 |
| Total Lines | 99 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | $collectiveInvitationsEnabled = $this->getConfigurationValue('agenda_collective_invitations'); |
||
| 33 | $subscriptionsEnabled = $this->getConfigurationValue('agenda_event_subscriptions'); |
||
| 34 | |||
| 35 | $this->addSql("UPDATE personal_agenda SET parent_event_id = NULL WHERE parent_event_id = 0 OR parent_event_id = ''"); |
||
| 36 | $this->addSql('UPDATE personal_agenda SET parent_event_id = NULL WHERE parent_event_id NOT IN (SELECT id FROM personal_agenda)'); |
||
| 37 | $this->addSql('DELETE FROM personal_agenda WHERE user NOT IN (SELECT id FROM user)'); |
||
| 38 | |||
| 39 | /** @var array<int, CCalendarEvent> $map */ |
||
| 40 | $map = []; |
||
| 41 | |||
| 42 | $userRepo = $this->container->get(UserRepository::class); |
||
|
|
|||
| 43 | |||
| 44 | $personalAgendas = $this->getPersonalEvents(); |
||
| 45 | |||
| 46 | $utc = new DateTimeZone('UTC'); |
||
| 47 | $oldNewEventIdMap = []; |
||
| 48 | |||
| 49 | /** @var array $personalAgenda */ |
||
| 50 | foreach ($personalAgendas as $personalAgenda) { |
||
| 51 | $oldParentId = (int) $personalAgenda['parent_event_id']; |
||
| 52 | $user = $userRepo->find($personalAgenda['user']); |
||
| 53 | |||
| 54 | $newParent = null; |
||
| 55 | |||
| 56 | if ($oldParentId && isset($map[$oldParentId])) { |
||
| 57 | $newParent = $map[$oldParentId]; |
||
| 58 | } |
||
| 59 | |||
| 60 | $calendarEvent = $this->createCCalendarEvent( |
||
| 61 | $personalAgenda['title'] ?: '-', |
||
| 62 | $personalAgenda['text'], |
||
| 63 | $personalAgenda['date'] ? new DateTime($personalAgenda['date'], $utc) : null, |
||
| 64 | $personalAgenda['enddate'] ? new DateTime($personalAgenda['enddate'], $utc) : null, |
||
| 65 | (bool) $personalAgenda['all_day'], |
||
| 66 | $personalAgenda['color'], |
||
| 67 | $user, |
||
| 68 | $newParent |
||
| 69 | ); |
||
| 70 | |||
| 71 | $map[$personalAgenda['id']] = $calendarEvent; |
||
| 72 | |||
| 73 | $this->entityManager->persist($calendarEvent); |
||
| 74 | $this->entityManager->flush(); |
||
| 75 | |||
| 76 | if ($collectiveInvitationsEnabled) { |
||
| 77 | $invitationsOrSubscriptionsInfo = []; |
||
| 78 | |||
| 79 | if ($subscriptionsEnabled) { |
||
| 80 | $subscriptionsInfo = $this->getSubscriptions((int) $personalAgenda['id']); |
||
| 81 | |||
| 82 | if (\count($subscriptionsInfo) > 0 |
||
| 83 | && 0 !== $personalAgenda['subscription_visibility'] |
||
| 84 | ) { |
||
| 85 | $invitationsOrSubscriptionsInfo = $subscriptionsInfo; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($invitationsOrSubscriptionsInfo) { |
||
| 90 | $calendarEvent |
||
| 91 | ->setInvitationType(CCalendarEvent::TYPE_SUBSCRIPTION) |
||
| 92 | ->setSubscriptionVisibility($personalAgenda['subscription_visibility']) |
||
| 93 | ->setSubscriptionItemId($personalAgenda['subscription_item_id']) |
||
| 94 | ->setMaxAttendees($invitationsOrSubscriptionsInfo[0]['max_attendees']) |
||
| 95 | ; |
||
| 96 | } else { |
||
| 97 | $invitationsInfo = $this->getInvitations($subscriptionsEnabled, (int) $personalAgenda['id']); |
||
| 98 | |||
| 99 | if (\count($invitationsInfo) > 0) { |
||
| 100 | $calendarEvent |
||
| 101 | ->setCollective((bool) $personalAgenda['collective']) |
||
| 102 | ->setInvitationType(CCalendarEvent::TYPE_INVITATION) |
||
| 103 | ; |
||
| 104 | |||
| 105 | $invitationsOrSubscriptionsInfo = $invitationsInfo; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | foreach ($invitationsOrSubscriptionsInfo as $invitationOrSubscriptionInfo) { |
||
| 110 | $inviteesOrSubscribersInfo = $this->getInviteesOrSubscribers($invitationOrSubscriptionInfo['id']); |
||
| 111 | |||
| 112 | foreach ($inviteesOrSubscribersInfo as $oldInviteeOrSubscriberInfo) { |
||
| 113 | $user = $this->entityManager->find(User::class, $oldInviteeOrSubscriberInfo['user_id']); |
||
| 114 | |||
| 115 | if ($user) { |
||
| 116 | $calendarEvent->addUserLink($user); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | $oldNewEventIdMap[$personalAgenda['id']] = $calendarEvent; |
||
| 122 | } |
||
| 123 | |||
| 124 | $this->entityManager->flush(); |
||
| 125 | |||
| 126 | if ($schema->hasTable('agenda_reminder')) { |
||
| 127 | if ($tblAgendaReminder->hasColumn('type')) { |
||
| 128 | $this->updateAgendaReminders($oldNewEventIdMap); |
||
| 129 | } |
||
| 251 |
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.