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