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