| Conditions | 17 |
| Paths | 432 |
| Total Lines | 104 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 70 | public function indexAction( |
||
| 71 | int $offset = 0, |
||
| 72 | int $limit = 25, |
||
| 73 | string $siteIdentifier = null, |
||
| 74 | string $nodeIdentifier = null, |
||
| 75 | string $accountIdentifier = null |
||
| 76 | ) { |
||
| 77 | if ($nodeIdentifier === '') { |
||
| 78 | $nodeIdentifier = null; |
||
| 79 | } |
||
| 80 | |||
| 81 | $numberOfSites = 0; |
||
| 82 | // In case a user can only access a single site, but more sites exists |
||
| 83 | $this->securityContext->withoutAuthorizationChecks(function () use (&$numberOfSites) { |
||
| 84 | $numberOfSites = $this->siteRepository->countAll(); |
||
| 85 | }); |
||
| 86 | $sites = $this->siteRepository->findOnline(); |
||
| 87 | if ($numberOfSites > 1 && $siteIdentifier === null) { |
||
| 88 | $domain = $this->domainRepository->findOneByActiveRequest(); |
||
| 89 | if ($domain !== null) { |
||
| 90 | $siteIdentifier = $this->persistenceManager->getIdentifierByObject($domain->getSite()); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | /** @var string[] $accounts */ |
||
| 95 | $accounts = []; |
||
| 96 | $accountIdentifiers = $this->nodeEventRepository->findAccountIdentifiers('live', $siteIdentifier ?: null, $nodeIdentifier ?: null); |
||
| 97 | foreach ($accountIdentifiers as $identifier) { |
||
| 98 | $user = $this->userService->getUser($identifier); |
||
| 99 | $accounts[$identifier] = $user ? $user->getName()->getLastName() . ', ' . $user->getName()->getFirstName() : $identifier; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** @var NodeEvent[] $events */ |
||
| 103 | $events = $this->nodeEventRepository |
||
| 104 | ->findRelevantEventsByWorkspace( |
||
| 105 | $offset, |
||
| 106 | $limit + 1, |
||
| 107 | 'live', |
||
| 108 | $siteIdentifier ?: null, |
||
| 109 | $nodeIdentifier, |
||
| 110 | $accountIdentifier ?: null |
||
| 111 | ) |
||
| 112 | ->toArray() |
||
| 113 | ; |
||
| 114 | |||
| 115 | $nextPage = null; |
||
| 116 | if (count($events) > $limit) { |
||
| 117 | $events = array_slice($events, 0, $limit); |
||
| 118 | |||
| 119 | $nextPage = $this->controllerContext |
||
| 120 | ->getUriBuilder() |
||
| 121 | ->setCreateAbsoluteUri(true) |
||
| 122 | ->uriFor( |
||
| 123 | 'Index', |
||
| 124 | [ |
||
| 125 | 'accountIdentifier' => $accountIdentifier, |
||
| 126 | 'nodeIdentifier' => $nodeIdentifier, |
||
| 127 | 'offset' => $offset + $limit, |
||
| 128 | 'siteIdentifier' => $siteIdentifier, |
||
| 129 | ] |
||
| 130 | ) |
||
| 131 | ; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** @var EventsOnDate[] $eventsByDate */ |
||
| 135 | $eventsByDate = []; |
||
| 136 | foreach ($events as $event) { |
||
| 137 | if ($event->getChildEvents()->count() === 0) { |
||
| 138 | continue; |
||
| 139 | } |
||
| 140 | $timestamp = $event->getTimestamp(); |
||
| 141 | $day = $timestamp->format('Y-m-d'); |
||
| 142 | if (!isset($eventsByDate[$day])) { |
||
| 143 | $eventsByDate[$day] = new EventsOnDate($timestamp); |
||
| 144 | } |
||
| 145 | |||
| 146 | $eventsOnThisDay = $eventsByDate[$day]; |
||
| 147 | $eventsOnThisDay->add($event); |
||
| 148 | } |
||
| 149 | |||
| 150 | $firstEvent = current($events); |
||
| 151 | if ($firstEvent === false) { |
||
| 152 | $node = $this->createContentContext('live')->getNodeByIdentifier($nodeIdentifier); |
||
| 153 | if ($node !== null) { |
||
| 154 | $firstEvent = [ |
||
| 155 | 'data' => [ |
||
| 156 | 'documentNodeLabel' => $node->getLabel(), |
||
| 157 | 'documentNodeType' => $node->getNodeType()->getName(), |
||
| 158 | ], |
||
| 159 | 'node' => $node, |
||
| 160 | 'nodeIdentifier' => $nodeIdentifier, |
||
| 161 | ]; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | $this->view->assignMultiple([ |
||
| 166 | 'accountIdentifier' => $accountIdentifier, |
||
| 167 | 'eventsByDate' => $eventsByDate, |
||
| 168 | 'firstEvent' => $firstEvent, |
||
| 169 | 'nextPage' => $nextPage, |
||
| 170 | 'nodeIdentifier' => $nodeIdentifier, |
||
| 171 | 'siteIdentifier' => $siteIdentifier, |
||
| 172 | 'sites' => $sites, |
||
| 173 | 'accounts' => $accounts, |
||
| 174 | ]); |
||
| 190 |