| Conditions | 16 |
| Paths | 264 |
| Total Lines | 55 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 37 | public function provide(Operation $operation, array $uriVariables = [], array $context = []): array |
||
| 38 | { |
||
| 39 | /** @var PartialPaginatorInterface $result */ |
||
| 40 | $result = $this->provider->provide($operation, $uriVariables, $context); |
||
| 41 | |||
| 42 | $request = $this->requestStack->getMainRequest(); |
||
| 43 | |||
| 44 | $studentView = $request ? $request->getSession()->get('studentview') : 'studentview'; |
||
| 45 | |||
| 46 | /** @var User|null $user */ |
||
| 47 | $user = $this->security->getUser(); |
||
| 48 | |||
| 49 | $isAllowToEdit = $user && ($user->hasRole('ROLE_ADMIN') || $user->hasRole('ROLE_CURRENT_COURSE_TEACHER')); |
||
| 50 | $isAllowToSessionEdit = $user && ($user->hasRole('ROLE_ADMIN') || $user->hasRole('ROLE_CURRENT_COURSE_TEACHER') || $user->hasRole('ROLE_CURRENT_COURSE_SESSION_TEACHER')); |
||
| 51 | |||
| 52 | $allowVisibilityInSession = $this->settingsManager->getSetting('course.allow_edit_tool_visibility_in_session'); |
||
| 53 | $session = $this->getSession(); |
||
| 54 | |||
| 55 | $results = []; |
||
| 56 | |||
| 57 | /** @var CTool $cTool */ |
||
| 58 | foreach ($result as $cTool) { |
||
| 59 | $toolModel = $this->toolChain->getToolFromName( |
||
| 60 | $cTool->getTool()->getName() |
||
| 61 | ); |
||
| 62 | |||
| 63 | if (!$isAllowToEdit && 'admin' === $toolModel->getCategory()) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | $resourceLinks = $cTool->getResourceNode()->getResourceLinks(); |
||
| 68 | |||
| 69 | if ($session && $allowVisibilityInSession) { |
||
| 70 | $sessionLink = $resourceLinks->findFirst( |
||
| 71 | fn (int $key, ResourceLink $resourceLink): bool => $resourceLink->getSession()?->getId() === $session->getId() |
||
| 72 | ); |
||
| 73 | |||
| 74 | if ($sessionLink) { |
||
| 75 | $resourceLinks->clear(); |
||
| 76 | $resourceLinks->add($sessionLink); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | if (!$isAllowToSessionEdit || 'studentview' === $studentView) { |
||
| 81 | $notPublishedLink = ResourceLink::VISIBILITY_PUBLISHED !== $resourceLinks->first()->getVisibility(); |
||
| 82 | |||
| 83 | if ($notPublishedLink) { |
||
| 84 | continue; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | $results[] = $cTool; |
||
| 89 | } |
||
| 90 | |||
| 91 | return $results; |
||
| 92 | } |
||
| 94 |