| Conditions | 3 |
| Paths | 3 |
| Total Lines | 72 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 136 | public function addToolsInCourse(CToolRepository $toolRepository, Course $course): Course |
||
| 137 | { |
||
| 138 | $tools = $this->getTools(); |
||
| 139 | $manager = $this->entityManager; |
||
| 140 | $toolVisibility = $this->settingsManager->getSetting('course.active_tools_on_create'); |
||
| 141 | |||
| 142 | $user = $this->security->getToken()->getUser(); |
||
| 143 | |||
| 144 | // Hardcoded tool list order |
||
| 145 | $toolList = [ |
||
| 146 | 'course_description', |
||
| 147 | 'document', |
||
| 148 | 'learnpath', |
||
| 149 | 'link', |
||
| 150 | 'quiz', |
||
| 151 | 'announcement', |
||
| 152 | 'gradebook', |
||
| 153 | 'glossary', |
||
| 154 | 'attendance', |
||
| 155 | 'course_progress', |
||
| 156 | 'agenda', |
||
| 157 | 'forum', |
||
| 158 | 'dropbox', |
||
| 159 | 'member', |
||
| 160 | 'group', |
||
| 161 | 'chat', |
||
| 162 | 'student_publication', |
||
| 163 | 'survey', |
||
| 164 | 'wiki', |
||
| 165 | 'notebook', |
||
| 166 | 'blog', |
||
| 167 | 'course_tool', |
||
| 168 | 'tracking', |
||
| 169 | 'course_setting', |
||
| 170 | 'course_maintenance', |
||
| 171 | ]; |
||
| 172 | $toolList = array_flip($toolList); |
||
| 173 | |||
| 174 | /** @var AbstractTool $tool */ |
||
| 175 | foreach ($tools as $tool) { |
||
| 176 | $visibility = in_array($tool->getName(), $toolVisibility, true); |
||
| 177 | $criteria = ['name' => $tool->getName()]; |
||
| 178 | // Skip global tools. |
||
| 179 | /*if ($tool->isCourseTool() === false) { |
||
| 180 | continue; |
||
| 181 | }*/ |
||
| 182 | if (!isset($toolList[$tool->getName()])) { |
||
| 183 | continue; |
||
| 184 | } |
||
| 185 | $toolEntity = $manager->getRepository('ChamiloCoreBundle:Tool')->findOneBy($criteria); |
||
| 186 | $position = $toolList[$tool->getName()] + 1; |
||
| 187 | |||
| 188 | $courseTool = new CTool(); |
||
| 189 | $courseTool |
||
| 190 | ->setTool($toolEntity) |
||
| 191 | ->setName($tool->getName()) |
||
| 192 | ->setPosition($position) |
||
| 193 | //->setCourse($course) |
||
| 194 | //->setImage($tool->getImage()) |
||
| 195 | //->setName($tool->getName()) |
||
| 196 | ->setVisibility($visibility) |
||
| 197 | //->setLink($tool->getLink()) |
||
| 198 | //->setTarget($tool->getTarget()) |
||
| 199 | ->setCategory($tool->getCategory()) |
||
| 200 | ; |
||
| 201 | |||
| 202 | //$this->toolRepository->createNodeForResource($courseTool, $user, $course->getResourceNode()); |
||
| 203 | $toolRepository->addResourceToCourse($courseTool, ResourceLink::VISIBILITY_PUBLISHED, $user, $course); |
||
| 204 | $course->addTools($courseTool); |
||
| 205 | } |
||
| 206 | |||
| 207 | return $course; |
||
| 208 | } |
||
| 235 |