Conditions | 16 |
Paths | 96 |
Total Lines | 86 |
Code Lines | 61 |
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 |
||
127 | public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array { |
||
128 | $scopes[] = new ScopeContext(IManager::SCOPE_ADMIN); |
||
|
|||
129 | $user = $this->session->getUser(); |
||
130 | if ($user !== null && $this->manager->isUserScopeEnabled()) { |
||
131 | $scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID()); |
||
132 | } |
||
133 | |||
134 | $ctx = new LogContext(); |
||
135 | $ctx |
||
136 | ->setScopes($scopes) |
||
137 | ->setEntity($this->entity) |
||
138 | ->setOperation($this->operation); |
||
139 | $this->logger->logFlowRequests($ctx); |
||
140 | |||
141 | $operations = []; |
||
142 | foreach ($scopes as $scope) { |
||
143 | $operations = array_merge($operations, $this->manager->getOperations($class, $scope)); |
||
144 | } |
||
145 | |||
146 | if ($this->entity instanceof IEntity) { |
||
147 | /** @var ScopeContext[] $additionalScopes */ |
||
148 | $additionalScopes = $this->manager->getAllConfiguredScopesForOperation($class); |
||
149 | foreach ($additionalScopes as $hash => $scopeCandidate) { |
||
150 | if ($scopeCandidate->getScope() !== IManager::SCOPE_USER || in_array($scopeCandidate, $scopes)) { |
||
151 | continue; |
||
152 | } |
||
153 | if ($this->entity->isLegitimatedForUserId($scopeCandidate->getScopeId())) { |
||
154 | $ctx = new LogContext(); |
||
155 | $ctx |
||
156 | ->setScopes([$scopeCandidate]) |
||
157 | ->setEntity($this->entity) |
||
158 | ->setOperation($this->operation); |
||
159 | $this->logger->logScopeExpansion($ctx); |
||
160 | $operations = array_merge($operations, $this->manager->getOperations($class, $scopeCandidate)); |
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | |||
165 | $matches = []; |
||
166 | foreach ($operations as $operation) { |
||
167 | $configuredEvents = json_decode($operation['events'], true); |
||
168 | if ($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) { |
||
169 | continue; |
||
170 | } |
||
171 | |||
172 | $checkIds = json_decode($operation['checks'], true); |
||
173 | $checks = $this->manager->getChecks($checkIds); |
||
174 | |||
175 | foreach ($checks as $check) { |
||
176 | if (!$this->check($check)) { |
||
177 | // Check did not match, continue with the next operation |
||
178 | continue 2; |
||
179 | } |
||
180 | } |
||
181 | |||
182 | $ctx = new LogContext(); |
||
183 | $ctx |
||
184 | ->setEntity($this->entity) |
||
185 | ->setOperation($this->operation) |
||
186 | ->setConfiguration($operation); |
||
187 | $this->logger->logPassedCheck($ctx); |
||
188 | |||
189 | if ($returnFirstMatchingOperationOnly) { |
||
190 | $ctx = new LogContext(); |
||
191 | $ctx |
||
192 | ->setEntity($this->entity) |
||
193 | ->setOperation($this->operation) |
||
194 | ->setConfiguration($operation); |
||
195 | $this->logger->logRunSingle($ctx); |
||
196 | return $operation; |
||
197 | } |
||
198 | $matches[] = $operation; |
||
199 | } |
||
200 | |||
201 | $ctx = new LogContext(); |
||
202 | $ctx |
||
203 | ->setEntity($this->entity) |
||
204 | ->setOperation($this->operation); |
||
205 | if (!empty($matches)) { |
||
206 | $ctx->setConfiguration($matches); |
||
207 | $this->logger->logRunAll($ctx); |
||
208 | } else { |
||
209 | $this->logger->logRunNone($ctx); |
||
210 | } |
||
211 | |||
212 | return $matches; |
||
213 | } |
||
244 |