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