Conditions | 18 |
Paths | 288 |
Total Lines | 71 |
Code Lines | 38 |
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 |
||
51 | public function provide(Operation $operation, array $uriVariables = [], array $context = []): array |
||
52 | { |
||
53 | /** @var PartialPaginatorInterface $result */ |
||
54 | $result = $this->provider->provide($operation, $uriVariables, $context); |
||
55 | |||
56 | $request = $this->requestStack->getMainRequest(); |
||
57 | $studentView = $request ? $request->getSession()->get('studentview') : 'studentview'; |
||
58 | |||
59 | /** @var User|null $user */ |
||
60 | $user = $this->security->getUser(); |
||
61 | |||
62 | $isAllowToEdit = $user && ($user->hasRole('ROLE_ADMIN') || $user->hasRole('ROLE_CURRENT_COURSE_TEACHER')); |
||
63 | $isAllowToEditBack = $isAllowToEdit; |
||
64 | $isAllowToSessionEdit = $user && ( |
||
65 | $user->hasRole('ROLE_ADMIN') || |
||
66 | $user->hasRole('ROLE_CURRENT_COURSE_TEACHER') || |
||
67 | $user->hasRole('ROLE_CURRENT_COURSE_SESSION_TEACHER') |
||
68 | ); |
||
69 | |||
70 | $allowVisibilityInSession = $this->settingsManager->getSetting('course.allow_edit_tool_visibility_in_session'); |
||
71 | $session = $this->getSession(); |
||
72 | $course = $this->getCourse(); |
||
73 | |||
74 | [$restrictToPositioning, $allowedToolName] = $this->shouldRestrictToPositioningOnly($user, $course->getId(), $session?->getId()); |
||
75 | |||
76 | $results = []; |
||
77 | |||
78 | /** @var CTool $cTool */ |
||
79 | foreach ($result as $cTool) { |
||
80 | if ($restrictToPositioning && $cTool->getTool()->getTitle() !== $allowedToolName) { |
||
81 | continue; |
||
82 | } |
||
83 | |||
84 | $toolModel = $this->toolChain->getToolFromName( |
||
85 | $cTool->getTool()->getTitle() |
||
86 | ); |
||
87 | |||
88 | if (!$isAllowToEdit && 'admin' === $toolModel->getCategory()) { |
||
|
|||
89 | continue; |
||
90 | } |
||
91 | |||
92 | $resourceLinks = $cTool->getResourceNode()->getResourceLinks(); |
||
93 | |||
94 | if ($session && $allowVisibilityInSession) { |
||
95 | $sessionLink = $resourceLinks->findFirst( |
||
96 | fn (int $key, ResourceLink $resourceLink): bool => $resourceLink->getSession()?->getId() === $session->getId() |
||
97 | ); |
||
98 | |||
99 | if ($sessionLink) { |
||
100 | // Set the session link as unique to include in repsonse |
||
101 | $resourceLinks->clear(); |
||
102 | $resourceLinks->add($sessionLink); |
||
103 | |||
104 | $isAllowToEdit = $isAllowToSessionEdit; |
||
105 | } else { |
||
106 | $isAllowToEdit = $isAllowToEditBack; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | if (!$isAllowToEdit || 'studentview' === $studentView) { |
||
111 | $notPublishedLink = ResourceLink::VISIBILITY_PUBLISHED !== $resourceLinks->first()->getVisibility(); |
||
112 | |||
113 | if ($notPublishedLink) { |
||
114 | continue; |
||
115 | } |
||
116 | } |
||
117 | |||
118 | $results[] = $this->transformer->transform($cTool); |
||
119 | } |
||
120 | |||
121 | return $results; |
||
122 | } |
||
166 |