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 |
||
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 | $isAllowToSessionEdit = $user && ($user->hasRole('ROLE_ADMIN') || $user->hasRole('ROLE_CURRENT_COURSE_TEACHER') || $user->hasRole('ROLE_CURRENT_COURSE_SESSION_TEACHER')); |
||
53 | |||
54 | $allowVisibilityInSession = $this->settingsManager->getSetting('course.allow_edit_tool_visibility_in_session'); |
||
55 | $session = $this->getSession(); |
||
56 | |||
57 | $results = []; |
||
58 | |||
59 | /** @var CTool $cTool */ |
||
60 | foreach ($result as $cTool) { |
||
61 | $toolModel = $this->toolChain->getToolFromName( |
||
62 | $cTool->getTool()->getName() |
||
63 | ); |
||
64 | |||
65 | if (!$isAllowToEdit && 'admin' === $toolModel->getCategory()) { |
||
66 | continue; |
||
67 | } |
||
68 | |||
69 | $resourceLinks = $cTool->getResourceNode()->getResourceLinks(); |
||
70 | |||
71 | if ($session && $allowVisibilityInSession) { |
||
72 | $sessionLink = $resourceLinks->findFirst( |
||
73 | fn (int $key, ResourceLink $resourceLink): bool => $resourceLink->getSession()?->getId() === $session->getId() |
||
74 | ); |
||
75 | |||
76 | if ($sessionLink) { |
||
77 | $resourceLinks->clear(); |
||
78 | $resourceLinks->add($sessionLink); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | if (!$isAllowToSessionEdit || 'studentview' === $studentView) { |
||
83 | $notPublishedLink = ResourceLink::VISIBILITY_PUBLISHED !== $resourceLinks->first()->getVisibility(); |
||
84 | |||
85 | if ($notPublishedLink) { |
||
86 | continue; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | $results[] = $cTool; |
||
91 | } |
||
92 | |||
93 | return $results; |
||
94 | } |
||
96 |