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